[RESOLVED] command button click ?
Hi Everyone , have a nice day
VB Code:
Private Sub Command1_Click()
Dim txt As String
Dim strline() As String
Dim word As String
Dim mean As String
Dim strvalues() As String
FF = FreeFile
Open App.Path & "\words.txt" For Input As FF
txt = Input(LOF(FF), FF) 'Read the whole file
Close FF
strline = Split(txt, vbNewLine)
For z = 0 To 3203
strvalues = Split((strline(z)), "|")
word = strvalues(0)
mean = strvalues(1)
Label1.Caption = word
Label2.Caption = mean
Next z
End Sub
Private Sub Command4_Click()
Unload Form1
End Sub
The code given above is what i have done till now . words.txt is basically a file having vocabulary in which one word is on each line and its meaning is separated by "|".
now what i want to do is that i have couple of more cummand buttons on my form like "next word" , "show meaning" , which should have capability of moving to next word without meanings display ... or show meanings .. and then proceed to next word .. but i donno how should i put that feasibility here ..
like i had in my mind if i could give something like .. within z loop
if commandbutton2_click = true
then label1.caption=word
but this doesnt work ..
i hope i making myself clear enuff
Regards and waiting for responce
Re: command button click ?
Try this....
VB Code:
Private Sub CommandButton2_Click()
Lable1.Caption = "Word"
End Sub
Also, if you double click the command button, it will have that format already written.
Re: command button click ?
Load the Array, and display the first elements data.
Re-do the 'For (z) Next' as a function of the new "Next" CommandButton.
Using the "Next" CommandButton, have it index the next element of the Array. Each press will increment the index value.
Re: command button click ?
as bruce said, but best if you declare (Dim) your array at form level (in the general section at the top) so that it keeps it's value for the whole time the form is open, then you only have to load it once when you open the form.
if you declare i as a static then it will also keep its value within that sub
and
Quote:
txt = Input(LOF(FF), FF)
VB Code:
txt = Input(LOF(FF), #FF)
Re: command button click ?
Here is how you would do it. However there is no error handling. You will need to add error handling codes e.g. check for bounds etc
VB Code:
Dim strline() As String '<-- Declare it at form level
' so that you donot need to open again and again
Dim cur As Long
Private Sub Command1_Click()
Dim txt As String
FF = FreeFile
Open App.Path & "\words.txt" For Input As FF
txt = Input(LOF(FF), #FF) 'Read the whole file
Close FF
strline = Split(txt, vbNewLine)
ShowWordMeaning
End Sub
Private Sub Command4_Click()
Unload Form1
End Sub
Private Sub Command5_Click() 'Previous word/menaing
cur = cur - 1
ShowWordMeaning
End Sub
Private Sub Command6_Click() 'Next word/meaning
cur = cur + 1
ShowWordMeaning
End Sub
Private Sub ShowWordMeaning()
'This sub shows word/meaning pair
'Modify as per your needs
Dim strvalues() As String
strvalues = Split((strline(cur)), "|")
Label1.Caption = strvalues(0) 'word
Label2.Caption = strvalues(1) 'meaning
End Sub
Pradeep :)