Results 1 to 10 of 10

Thread: Help with code ..

  1. #1

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

    Talking Help with code ..

    well i want to create a simple GUI . i have a three command buttons naming
    ( start , start from line , Quit ) and i have a text file( words.txt) of 5014 lines.
    now i want that when i click start . program should pick up the very first line of the text file and prompts the content of whole first line as a window ( or message box ) .. keeps it there for almost 10 seconds and then refreashes that very window with the next line of text file and keeps on doing it till 5014th line or user clicks "Quit"

    and incase at start up user clicks " start from line "
    it prompt for a line number from user and at input . repeat the previous procedure starting from this line number ( which user have just given ) and keeps running just like before

    well basically text file contains vocabulary . and this very program is sorta help to learn that vocabulary while user is using computer .
    i hope i ll be making lil sense ..
    regards and waiting for reply ..
    Last edited by Dastard; Jan 15th, 2006 at 12:27 PM.

  2. #2
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    Re: Help with code ..

    First make you interface. This is how I laid mine out:


    Then When the person hits start:
    VB Code:
    1. Private Sub cmdStart_Click()
    2.  
    3.     Open txtInputFile For Input As #1
    4.    
    5.         'Skip through file to starting point
    6.         For i = 1 To txtStartFrom
    7.             Line Input #1, strTemp
    8.         Next i
    9.        
    10.         'Display lines from starting point
    11.         For i = txtStartFrom To EOF(1)
    12.             Line Input #1, strVocab
    13.             txtDisplay = strVocab
    14.             Sleep 2000 'Pause 2 seconds
    15.         Next i
    16.  
    17. End Sub
    PHP in your FACE!

  3. #3
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    213

    Re: Help with code ..

    Try modifying the "Tip of the Day" form.

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Help with code ..

    well, that may be very tedious. my suggestion will be to load the text file into an string array (line by line) and then display them accordingly (from LBound of Array to UBound of Array).

    Use a seperate window instead of MsgBox because then the user wont be able to click the "Quit" button. use a timer event to load/unload the Display form for the defined time.
    Show Appreciation. Rate Posts.

  5. #5
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    Re: Help with code ..

    Quote Originally Posted by Harsh Gupta
    my suggestion will be to load the text file into an string array (line by line) and then display them accordingly (from LBound of Array to UBound of Array). Use a seperate window instead of MsgBox because then the user wont be able to click the "Quit" button. use a timer event to load/unload the Display form for the defined time.
    I see some isn't lazy about writing code and taking shortcuts
    PHP in your FACE!

  6. #6

  7. #7

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

    Re: Help with code ..

    Its awesome martinliss . thats what exactly i had in my mind . thanks a lot guru .. i m still wondering how is it working when all the buttons have same name .. excellent use of resources .. well just need to ask two lil things . . first . it doesnt immediately quit when i click quit button .. it sorta "stops responding" and second is this programming using much my pc resources i feel like that it is acctually caz i don have much virtual memory in my computer ..

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help with code ..

    Try this code instead. BTW Command1 is what's called a control array - basically copies of the same control that share code.

    VB Code:
    1. Option Explicit
    2. 'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    3. Dim mbQuit As Boolean
    4.  
    5. Private Sub Command1_Click(Index As Integer)
    6.  
    7.     Dim intLine As Integer
    8.    
    9.     Select Case Index
    10.         Case 0
    11.             ReadFile
    12.         Case 1
    13.             intLine = InputBox("Please enter the line to start from", "Start From", 1)
    14.             ' There should be some validation of intLine here
    15.             ReadFile intLine
    16.         Case 2
    17.             mbQuit = True
    18.             DoEvents
    19.             Unload Me
    20.     End Select
    21.    
    22. End Sub
    23. Public Sub ReadFile(Optional StartPoint As Integer = 1)
    24.  
    25.     Dim ff As Integer
    26.     Dim lngCount As Long
    27.     Dim strLine As String
    28.     Dim dblClock As Double
    29.    
    30.     ff = FreeFile
    31.    
    32.     Open "C:\temp\test.txt" For Input As ff
    33.    
    34.     Do Until EOF(ff)
    35.         lngCount = lngCount + 1
    36.         Line Input #ff, strLine
    37.         If lngCount >= StartPoint Then
    38.             Label1.Caption = strLine
    39.             DoEvents
    40.             dblClock = Timer
    41.             While Timer < dblClock + 10
    42.                 DoEvents
    43.                 If mbQuit Then
    44.                     Unload Me
    45.                     dblClock = 0
    46.                 End If
    47.             Wend
    48.         End If
    49.     Loop
    50.    
    51.     Close ff
    52.  
    53. End Sub

  9. #9

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

    Resolved Re: Help with code ..

    Thanks a lot . its working fine .. just tell me how can i change the font of text which is being displayed in pop up window there ... its quite small . besides that .. thread is resolved ...

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help with code ..

    By "pop up window" do you mean the InputBox message? If so, I've attached a form that looks like an inputbox that you can modify however you want.

    I see that you attempted to indicate that the thread was resolved. Thanks, but the way to do that however is to pull down the Thread Tools menu and click the Mark Thread Resolved button.
    Attached Files Attached Files

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