Results 1 to 5 of 5

Thread: [RESOLVED] command button click ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Lahore
    Posts
    214

    Resolved [RESOLVED] command button click ?

    Hi Everyone , have a nice day

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim txt As String
    3. Dim strline() As String
    4. Dim word As String
    5. Dim mean As String
    6. Dim strvalues() As String
    7. FF = FreeFile
    8. Open App.Path & "\words.txt" For Input As FF
    9.              txt = Input(LOF(FF), FF)    'Read the whole file
    10.         Close FF
    11.            strline = Split(txt, vbNewLine)
    12.   For z = 0 To 3203
    13.                     strvalues = Split((strline(z)), "|")
    14.                   word = strvalues(0)
    15.                   mean = strvalues(1)
    16.                   Label1.Caption = word
    17.                   Label2.Caption = mean
    18.     Next z
    19.          
    20. End Sub
    21.  
    22. Private Sub Command4_Click()
    23. Unload Form1
    24. 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

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: command button click ?

    Try this....

    VB Code:
    1. Private Sub CommandButton2_Click()
    2.       Lable1.Caption = "Word"
    3. End Sub

    Also, if you double click the command button, it will have that format already written.
    My usual boring signature: Something

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    txt = Input(LOF(FF), FF)
    VB Code:
    1. txt = Input(LOF(FF), #FF)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. Dim strline() As String    '<-- Declare it at form level
    2.                            '    so that you donot need to open again and again
    3. Dim cur As Long
    4.  
    5. Private Sub Command1_Click()
    6.     Dim txt As String
    7.    
    8.     FF = FreeFile
    9.     Open App.Path & "\words.txt" For Input As FF
    10.          txt = Input(LOF(FF), #FF)    'Read the whole file
    11.     Close FF
    12.     strline = Split(txt, vbNewLine)
    13.     ShowWordMeaning
    14. End Sub
    15.  
    16. Private Sub Command4_Click()
    17. Unload Form1
    18. End Sub
    19.  
    20. Private Sub Command5_Click()    'Previous word/menaing
    21.     cur = cur - 1
    22.     ShowWordMeaning
    23. End Sub
    24.  
    25. Private Sub Command6_Click()    'Next word/meaning
    26.     cur = cur + 1
    27.     ShowWordMeaning
    28. End Sub
    29.  
    30. Private Sub ShowWordMeaning()
    31.     'This sub shows word/meaning pair
    32.     'Modify as per your needs
    33.    
    34.     Dim strvalues() As String
    35.    
    36.     strvalues = Split((strline(cur)), "|")
    37.     Label1.Caption = strvalues(0)   'word
    38.     Label2.Caption = strvalues(1)   'meaning
    39. End Sub


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width