|
-
Sep 9th, 2000, 12:00 PM
#1
Thread Starter
Member
ok this is a stupid question but just on of those pain-in-the-ass things you can't do:
i have a listbox which generates a random amount of random strings, when i close the form the strings are generated again,which i don't want, at the moment i'm kinda doing this
udtEMPL.Em1 = ListBox. ??????
then for the next item in the listbox i would have
udtEMPL.Em2 = Listbox. ?????
i want this to be done automatically by the prog.
can anyone help?
thanks
-
Sep 9th, 2000, 12:08 PM
#2
_______
<?>
Code:
Generate your strings and store them in an array:
Dim myArr()
For i = whatever to whatever
ReDim Preserver myArr(i)
myArr(i) = i & (rnd * 100) + 1
next i
for i = lbound(myArr) to uBound(myArr)
list1.additem myArr(i)
next i
'You could then store your array in a file it wanted
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 9th, 2000, 12:11 PM
#3
Thread Starter
Member
-
Sep 9th, 2000, 01:07 PM
#4
Thread Starter
Member
but... it doesn't add integers it adds strings, so that doesn't work, here is my existing code:
Sub GENITEMZ()
Employeez.Clear
Empler.Clear
HMNY = Int((8 * Rnd) + 1)
Dim Counter As Integer
Do Until Counter = HMNY
RAN = Int((8) * Rnd)
If RAN = 0 Then Employeez.AddItem ("Manual Labourer")
If RAN = 1 Then Employeez.AddItem ("Manual Labourer")
If RAN = 2 Then Employeez.AddItem ("Manual Labourer")
If RAN = 3 Then Employeez.AddItem ("Manual Labourer")
If RAN = 4 Then Employeez.AddItem ("Bodyguard")
If RAN = 5 Then Employeez.AddItem ("Bodyguard")
If RAN = 6 Then Employeez.AddItem ("Scientist")
If RAN = 7 Then Employeez.AddItem ("Navigator")
Counter = Counter + 1
Loop
End Sub
-
Sep 9th, 2000, 01:18 PM
#5
_______
<?>
what exactly are you looking for as a result of calling
your function?
Give me an example of what the correct situtaion would yield.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 9th, 2000, 01:21 PM
#6
Thread Starter
Member
that code works, the listbox would contain a random number of strings (which works) and when the form is closed and opened again the listbox would contain the same strings in the same order (which doesn't work)
-
Sep 9th, 2000, 01:36 PM
#7
_______
<?>
forgot one little thing
you need to put this above the Rnd functions then it will work
Randomize
Code:
Option Explicit
Sub GENITEMZ()
Dim ran As Integer
Dim HMNY As Integer
Employeez.Clear
Empler.Clear
Randomize
HMNY = Int((8 * Rnd) + 1)
Dim Counter As Integer
Do Until Counter = HMNY
Randomize
ran = Int((8) * Rnd)
If ran = 0 Then Employeez.AddItem ("Manual Labourer")
If ran = 1 Then Employeez.AddItem ("Manual Labourer")
If ran = 2 Then Employeez.AddItem ("Manual Labourer")
If ran = 3 Then Employeez.AddItem ("Manual Labourer")
If ran = 4 Then Employeez.AddItem ("Bodyguard")
If ran = 5 Then Employeez.AddItem ("Bodyguard")
If ran = 6 Then Employeez.AddItem ("Scientist")
If ran = 7 Then Employeez.AddItem ("Navigator")
Counter = Counter + 1
Loop
End Sub
Private Sub Form_Load()
Call GENITEMZ
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 9th, 2000, 03:01 PM
#8
Thread Starter
Member
that works, but when i close the form and then re-open the form the strings in the list box have been generated again.
-
Sep 9th, 2000, 03:56 PM
#9
Thread Starter
Member
-
Sep 9th, 2000, 03:58 PM
#10
_______
<?>
are you saying you want to generate only once and then
save the strings on exit for the next time you open?
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 9th, 2000, 04:27 PM
#11
Thread Starter
Member
-
Sep 9th, 2000, 04:46 PM
#12
Thread Starter
Member
-
Sep 9th, 2000, 04:59 PM
#13
_______
<?>
what's with this anyone?
it takes time to write code..don't be so impatient.
sometimes it takes hours to get answers.
'this will load your strings once and only once
'saves them to a file and reloads
Code:
Option Explicit
Sub GENITEMZ()
Dim ran As Integer
Dim HMNY As Integer
employeez.Clear
empler.Clear
Randomize
HMNY = Int((8 * Rnd) + 1)
Dim Counter As Integer
Do Until Counter = HMNY
Randomize
ran = Int((8) * Rnd)
If ran = 0 Then employeez.AddItem ("Manual Labourer")
If ran = 1 Then employeez.AddItem ("Manual Labourer")
If ran = 2 Then employeez.AddItem ("Manual Labourer")
If ran = 3 Then employeez.AddItem ("Manual Labourer")
If ran = 4 Then employeez.AddItem ("Bodyguard")
If ran = 5 Then employeez.AddItem ("Bodyguard")
If ran = 6 Then employeez.AddItem ("Scientist")
If ran = 7 Then employeez.AddItem ("Navigator")
Counter = Counter + 1
Loop
Call SaveMyListBox
End Sub
Public Sub SaveMyListBox()
'Save the contents
Dim i As Integer
Open "C:\my documents\myListBox.txt" For Output As #1
For i = 0 To employeez.ListCount - 1
Print #1, employeez.List(i)
Next i
Close #1
End Sub
Public Sub LoadMyListBox()
'Load the contents
Dim sListing As String, i As Integer
Open "C:\my documents\myListBox.txt" For Input As #1
Do While Not EOF(1)
Input #1, sListing
employeez.AddItem sListing
Loop
Close #1
End Sub
Private Sub Form_Load()
Dim sFile$
sFile = "C:\my documents\mylistbox.txt"
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(sFile$) = True Then
Call LoadMyListBox
Else
Call GENITEMZ
End If
Set fs = Nothing
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 9th, 2000, 06:53 PM
#14
Thread Starter
Member
sorry, just often people will start helping then get fed up and bugger off, thanks anyway.
is there anyway it could be done without saving it?
-
Sep 17th, 2000, 04:36 AM
#15
Thread Starter
Member
i mean when i close that particular form the whole program is not closed because the main form can't be, i just want the listbox contents to be saved while the program is running - you know just have it stored under a public type...
-
Sep 17th, 2000, 07:39 AM
#16
_______
<?>
Code:
'if you add a public variable (array)
Option Explicit
Public myArr()
'*********change loading and unload the file
'Save the contents
Dim i As Integer
For i = 0 To employeez.ListCount - 1
ReDim Preserve myArr(i)
myArr(i) = employeez.List(i)
Next i
Close #1
End Sub
Public Sub LoadMyListBox()
'Load the contents
Dim i As Integer
For i = LBound(myArr) To UBound(myArr)
employeez.AddItem myArr(i)
Next i
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 17th, 2000, 07:57 AM
#17
Thread Starter
Member
Public myArr()
'*********change loading and unload the file
'Save the contents
Dim i As Integer
For i = 0 To employeez.ListCount - 1
ReDim Preserve myArr(i)
myArr(i) = employeez.List(i)
Next i
Close #1
End Sub
i put this in a module and it says: invalid outside procedure, it doesn't work in the form's code either
-
Sep 17th, 2000, 08:39 AM
#18
_______
<?>
Ok..I will yank your code down and see what is happening.
Is it the same as in this post or have you changed it.
If so give me your new stuff.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 17th, 2000, 08:54 AM
#19
_______
<?>
Code:
'
'works..I tested it
'
'this goes in a bas module
Option Explicit
Public myArr()
'This goes in form1
Option Explicit
Sub GENITEMZ()
Dim ran As Integer
Dim HMNY As Integer
employeez.Clear
'empler.Clear
Randomize
HMNY = Int((8 * Rnd) + 1)
Dim Counter As Integer
Do Until Counter = HMNY
Randomize
ran = Int((8) * Rnd)
If ran = 0 Then employeez.AddItem ("Manual Labourer")
If ran = 1 Then employeez.AddItem ("Manual Labourer")
If ran = 2 Then employeez.AddItem ("Manual Labourer")
If ran = 3 Then employeez.AddItem ("Manual Labourer")
If ran = 4 Then employeez.AddItem ("Bodyguard")
If ran = 5 Then employeez.AddItem ("Bodyguard")
If ran = 6 Then employeez.AddItem ("Scientist")
If ran = 7 Then employeez.AddItem ("Navigator")
Counter = Counter + 1
Loop
Call SaveMyListBox
End Sub
Public Sub SaveMyListBox()
Dim i As Integer
For i = 0 To employeez.ListCount - 1
ReDim Preserve myArr(i)
myArr(i) = employeez.List(i)
Next i
End Sub
Public Sub LoadMyListBox()
'Load the contents
Dim i As Integer
For i = LBound(myArr) To UBound(myArr)
employeez.AddItem myArr(i)
Next i
End Sub
Private Sub Command1_Click()
Unload me
Load Form2
Form2.Show
End Sub
Private Sub Form_Load()
On Error GoTo QuitNow:
Debug.Print UBound(myArr)
Call LoadMyListBox
On Error GoTo 0
Exit Sub
QuitNow:
Call GENITEMZ
End Sub
'this goes in form2
Option Explicit
Private Sub Command1_Click()
Unload Me
Load Form1
Form1.Show
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 17th, 2000, 11:16 AM
#20
You can shorten all of those If...Then's with a Choose() function.
Code:
employeez.AddItem Choose(Int(Rnd * 8) + 1, "Manual Labourer", "Manual Labourer", "Manual Labourer", "Manual Labourer", "Bodyguard", "Bodyguard", "Scientist", "Navigator")
-
Sep 30th, 2000, 03:18 PM
#21
Thread Starter
Member
this comes a bit late but i have been away during the week: thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|