|
Does that account your using have access to the share on the other machine?
I should ask, does the account have the proper rights to the share? You can't use just read-only. The account must have read and write access...
RageInTheMachine9532
|
|
|
|
|
I am trying to get 5 random numbers between the numbers of 1 to 50 using vb.net. This is what I came up with so far:
Dim Array(4) As Integer
Dim Counter As Integer
For Counter = 0 To 4
Array(Counter) = CInt(Int((49 * Rnd()) + 1))
Next
Array.Sort(Array)
lbl1.Text = Array(0)
lbl2.Text = Array(1)
lbl3.Text = Array(2)
lbl4.Text = Array(3)
lbl5.Text = Array(4)
This code actually works but the thing is that it can pick the same number twice. I need all 5 numbers to be different. How can I achieve this?
Please help and thanks in advance.
Beginner in VB.NET
|
|
|
|
|
I've not put this in a compiler to check the syntax, so appologies in advance if I'm mistyped something. Here is a solution.
On each iteration the previous values are checked with the current random value and if they match a new random number is generated, this checking continues until there are no matches, at which point the value is put in the array and it moves on to the next element, like in your original code.
Dim Array(4) As Integer
Dim Counter As Integer
Dim CheckCounter As Integer
Dim Current As Integer
Dim IsOkay As Boolean
For Counter = 0 To 4
IsOkay = True
Do
Current = CInt(Int((49 * Rnd()) + 1))
For CheckCounter = 0 to Counter-1
If Current = Array(CheckCounter)
IsOkay = False
End If
Next
Loop While IsOkay = False
Array(Counter) = Current
Next
Array.Sort(Array)
lbl1.Text = Array(0)
lbl2.Text = Array(1)
lbl3.Text = Array(2)
lbl4.Text = Array(3)
lbl5.Text = Array(4)
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
Yes with a few added lines which are in bold:
Dim Array(4) As Integer<br />
Dim Counter As Integer<br />
Dim CheckCounter As Integer<br />
Dim Current As Integer<br />
Dim isOkay As Boolean<br />
For Counter = 0 To 4<br />
isOkay = True<br />
Do<br />
Current = CInt(Int(49 * Rnd()) + 1)<br />
For CheckCounter = 0 To Counter - 1<br />
If Current = Array(CheckCounter) Then<br />
isOkay = False<br />
Exit For<br />
Else<br />
isOkay = True<br />
End If<br />
Next<br />
Loop While isOkay = False<br />
Array(Counter) = Current<br />
Next<br />
Array.Sort(Array)<br />
lbl1.Text = Array(0)<br />
lbl2.Text = Array(1)<br />
lbl3.Text = Array(2)<br />
lbl4.Text = Array(3)<br />
lbl5.Text = Array(4)
I had to add the else isOkay = true because with your origional code, once isOkay was set to false it was stuck in the loop. Which has solved my problem.
Thanks again
Beginner in VB.NET
|
|
|
|
|
Britnt7 wrote:
had to add the else isOkay = true because with your origional code, once isOkay was set to false it was stuck in the loop
Sorry, about that. I just typed it in the text box on the web site and it looked okay. Just goes to show that testing is really important.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
Is it possible to pull from a list or array (1-50) so when the number is chosen, it is taken out of the list or array? Therefore it cannot be chosen again for the next random number. I didn't want the same number to be chosen twice at all.
That is what I intended to do but your code works as well. Just curious.
Beginner in VB.NET
|
|
|
|
|
Britnt7 wrote:
Is it possible to pull from a list or array (1-50) so when the number is chosen, it is taken out of the list or array?
Yes, of course. Here is an example (It is a complete console application if you want to test it)
Module Module1
Sub Main()
' Randomize the random number generator so it
' produces different results each time
Randomize()
' Declare variables
Dim Array(4) As Integer
Dim Counter As Integer
Dim PossibleValues As ArrayList
Dim Current As Integer
Dim Index As Integer
' Build a list of possible values
PossibleValues = New ArrayList(50)
For Counter = 0 To 49
PossibleValues.Add(Counter)
Next
' Populate the Array of random values, removing
' each from the list of PossibleValues as they
' get used
For Counter = 0 To 4
Index = Int(PossibleValues.Count * Rnd())
Current = CInt(PossibleValues(Index))
Array(Counter) = Current
PossibleValues.RemoveAt(Counter)
Next
'Print out the Array
Array.Sort(Array)
Console.WriteLine(Array(0))
Console.WriteLine(Array(1))
Console.WriteLine(Array(2))
Console.WriteLine(Array(3))
Console.WriteLine(Array(4))
Console.ReadLine()
End Sub
End Module
How it works is that a list of all possible values is built and as each possible value is randomly selected it is removed from the list of possible values. The Random number that is generated is used as the index into the list of PossibleValues. This technique could be used for any list of PossibleValues (say Months of the year, Days of the Week, Lottery Numbers, etc.) where you don't want to get the same value twice.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
Yes! There was one problem in your code. When I was debugging through your code, I had to change one line:
PossibleValues.RemoveAt(Counter)
This removes the Counter from the arraylist which in fact it should remove the number that was chosen for the new array from the arraylist. I did this by:
PossibleValues.RemoveAt(Index)
This solves the problem.
It is definetly good enough for me but I was trying to do the impossible. This was my vision as to what should happen.
You have 5 numbers (1,2,3,4,5)
Randomly select a number from those five
Lets say 3 - now the numbers left are (1,2,4,5)
Randomly select a number from those four
Lets say 4 - now the numbers left are (1,2,5)
Randomly select a number from those three
Lets say 2 - now the numbers left are (1,5)
Your array is (3,4,2)
Your code above does this but the random number selected is an index and not the true number. In your case, if the number chosen is a 4 then index = 4 and the number would be 5.
Now the array above has changed to (3,4,5)
I think this is impossible to mimick a true say lottery drawing.
Thanks for all of your help.;)
|
|
|
|
|
You could probably use the arraylist to check whether the same number has already been used.
Dim arr as New ArrayList
Dim Counter As Integer
Dim iCur as Integer
For Counter = 0 To 4
icur = CInt(Int((49 * Rnd()) + 1))
while arr.contains(icur)
icur = CInt(Int((49 * Rnd()) + 1))
end while
arr.add(icur)
Next
arr.sort()
lbl1.Text = arr(0)
lbl2.Text = arr(1)
lbl3.Text = arr(2)
lbl4.Text = arr(3)
lbl5.Text = arr(4)
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
Support Bone
It's a weird Life
|
|
|
|
|
Yes, this takes out the boolean that was used in this forum above.
Read the rest that is posted under this forum to see if you have the impossible answer.
Thanks
|
|
|
|
|
Oh, there was one line that you have forgotten to make this work. After:
arr.add(icur)
I had to add:
Array(Counter) = iCur
to add the number to the origional array.;)
|
|
|
|
|
Hi to all,
How can I paint the background of the MDIParent from by myself. Default backgroundImage property draws image multiple if it is smallest that the size of the form. And I need to paint the small image at the center of the form.
Regards,
Alex
|
|
|
|
|
What is the problem in using Paint event of the form?
|
|
|
|
|
The problem is: when I try to paint some image on the form there are no results! If I change isMDIContainer property to false, then all works fine. But if isMDIContainer=true then I can't see any results of OnPaint or OnPaintBackground functions call.
Regards,
Alex
|
|
|
|
|
|
im trying to make a slideshow kind of app in vb6 thats similar to MS powerpoint.
my idea is to use the MDI wizard and make each new child form as a slide.
my prob is , how do i access these children when i click on , say, a button called , run slideshow.
there must be some array of forms like MDI list where all the forms and their info must be stored right?
if i get that , then all i have to do is run a for loop and use form.show() !
any clues??
|
|
|
|
|
VB6 has an intrinsic collection called Forms. Use Forms(index) to index all the forms you have loaded (including the MDI Parent!). Forms.Count() will give you the number of forms in the collection.
RageInTheMachine9532
|
|
|
|
|
I am trying to create the com based add in for office to integrate the program our company has been developing.
I encounter the problem when you save "ActiveDocument.Save"
and "ActiveDocument.Saved" becomes false when activating another dialog or something else.
Does any one meet this problem and managed to solve?
Shi
|
|
|
|
|
There is a dll which I interface with using this code
thedll.SetReceiveCallback(new ApplicationClass.receiveCallback(MessageReceived));
At which point I can then declare a function and recieve info from the dll!
public virtual void MessageReceived(XmlDocument TheXmlMessage)
{
//Information from the dll
}
The problem is that I can't seem to get it to work in VB.Net!
Where am I going wrong please!
|
|
|
|
|
So far, you've posted the C# code, but not the VB code your using. With what you've posted, it should look something like this:
thedll.SetReceiveCallback(New ApplicationClass.receiveCallback(MessageReceived))
.
.
.
Public Overridable Sub MessageReceived(TheXmlMessage As XmlDocument)
' Information from the .dll
End Sub
We'll need to see the C# code your using and the VB code you translated it to so we can see what went wrong.
RageInTheMachine9532
|
|
|
|
|
Cheers for your help!
I have been playing around with it all day (well not all day) and finally got the end result which works so I appreciate the pointers!
Sorry I didn't post any of my VB code in but that was mostly because I didn't really have any!
Basically, I was trying to use the same code in C# but using VB.Net!
Here is my result and you can see that you have indeed helped me!
thedll.SetReceiveCallback(AddressOf MessageReceived)
Public Overridable Sub MessageReceived(ByVal XmlMessage As XmlDocument)
' Information from the .dll
MsgBox("hello")
End Sub
|
|
|
|
|
Hi,
I need to create a small EXE console application (NO USER INTERFACE) it will execute and when it has finish the code it will close.
I need a console app that will OUTPUT a value on a parallel port for 3 seconds, then quit. THAT's it.
Any Idea how to write this simple console APP ?
I'm using WINDOWS 2000 and VISUAL BASIC 6
Thank you.
|
|
|
|
|
VB6 can't build a console application directly. But it can build a normal Windows app that doesn't have an interface. On top of that, your app can't get direct access to the parallel port without a helper .DLL. See http://www.logix4u.net/[^] for a good example.
RageInTheMachine9532
|
|
|
|
|
Hi,
Thank you for your help, I was searching the web for info, and I saw yesterday the http://www.logix4u.net/, but its not working, my VB does'nt see the DLL. Did you try it ?
I have downloaded their test project and I can't make it run properly. Do I have to load in VB the DLL, or how can I access it.
I've only copied the DLL file to my project folder and in the windows system32 folder.
Any help will be appreciated.
Thank you,
Aldrin,
|
|
|
|
|
Yep and it works perfectly. You should post some of your code so we can see what you're doing right/wrong. Also, any error messages that you get should be included.
All you have to do to use it is copy the .dll to the system32 folder and put this code in a module or at the top of a form class:
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Now, to use the functions:
Dim inFromPort As Long
Dim outToPort As Long
inFromPort = Inp(&H3F8) ' Or whatever port your trying to use.
Out &H3F8, outToPort ' Or whatever port and value your try to output.
RageInTheMachine9532
|
|
|
|