Results 1 to 12 of 12

Thread: Code Problem [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154

    Code Problem [RESOLVED]

    VB Code:
    1. If Form3.Text1.Text = "" Then
    2. On Error GoTo 1
    3.     With CD1
    4.         .DialogTitle = "Open Name File"
    5.         .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    6.         .ShowOpen
    7. Dim sText As String
    8.     Dim x As Integer
    9.     x = FreeFile
    10.     On Error Resume Next
    11.     Open .FileName For Input As #x
    12.     While Not EOF(x)
    13.         Input #x, sText$
    14.             If sText$ = "" Then
    15.             Exit Sub
    16.             Else
    17.             List1.AddItem sText$
    18.             DoEvents
    19.             End If
    20.     Wend
    21.     Close #x
    22.         End With
    23. Label1.Caption = "Word's: " & List1.ListCount
    24.     Exit Sub
    25. 1
    26. End If
    27. End Sub
    28. Else
    29. If Check1.Value = vbChecked Then
    30. On Error GoTo 1
    31.     With CD1
    32.         .DialogTitle = "Open Name File"
    33.         .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    34.         .ShowOpen
    35. Dim sText As String
    36.     Dim x As Integer
    37.     x = FreeFile
    38.     On Error Resume Next
    39.     Open .FileName For Input As #x
    40.     While Not EOF(x)
    41.         Input #x, sText$
    42.             If sText$ = "" Then
    43.             Exit Sub
    44.             Else
    45.             List1.AddItem sText$
    46.             DoEvents
    47.             End If
    48.     Wend
    49.     Close #x
    50.         End With
    51. Label1.Caption = "Word's: " & List1.ListCount
    52.     Exit Sub
    53. 1
    54. End If
    55. End Sub

    This is my code im using but somehwere in it its really messed up. I appreciate all the help and would love some with this problem
    Last edited by $peed & $ex; Jan 11th, 2003 at 04:06 PM.

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    I dunno it jsut wont work with that code it always has compile errors and **** and im sure its messed up somehwere

  4. #4

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    Well its under command btuoon 1 but I want it to do 2 diferent things if there selected and stuff right...Thx man

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Something like this?
    VB Code:
    1. Dim sText As String
    2.     Dim intFileNum As Integer
    3.     Dim sText As String
    4.  
    5.     If Form3.Text1.Text = "" Then
    6.         'On Error GoTo 1 (This is very bad practice)
    7.         With CD1
    8.             .DialogTitle = "Open Name File"
    9.             .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    10.             .ShowOpen
    11.             intFileNum = FreeFile
    12.             On Error Resume Next
    13.             Open .FileName For Input As #intFileNum
    14.             While Not EOF(intFileNum)
    15.                 Input #intFileNum, sText$
    16.                 If sText$ = "" Then
    17.                     Exit Sub
    18.                 Else
    19.                     List1.AddItem sText$
    20.                     DoEvents
    21.                 End If
    22.             Wend
    23.             Close #intFileNum
    24.         End With
    25.     Else
    26.         If Check1.Value = vbChecked Then
    27.             With CD1
    28.                 .DialogTitle = "Open Name File"
    29.                 .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    30.                 .ShowOpen
    31.                 intFileNum = FreeFile
    32.                 On Error Resume Next
    33.                 Open .FileName For Input As #intFileNum
    34.                 While Not EOF(intFileNum)
    35.                     Input #intFileNum, sText$
    36.                         If sText$ = "" Then
    37.                             Exit Sub
    38.                         Else
    39.                             List1.AddItem sText$
    40.                             DoEvents
    41.                         End If
    42.                 Wend
    43.                 Close #intFileNum
    44.             End With
    45.         End If
    46.     End If
    47.    
    48.     Label1.Caption = "Word's: " & List1.ListCount

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    Ok well that code comes up and says that stext as string compile error duplicate declariation in current scope?Thx man

  8. #8

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    What do u mean?Remove jsut 1 of what?

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    One of the duplicate Dim statements. Change this
    VB Code:
    1. Dim sText As String
    2.     Dim intFileNum As Integer
    3.     Dim sText As String
    to this
    VB Code:
    1. Dim sText As String
    2.     Dim intFileNum As Integer

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154
    Ok kewl thx man helped me out big time

  12. #12
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You're welcome. BTW it looks to me that this is the same.
    VB Code:
    1. Dim sText As String
    2.     Dim intFileNum As Integer
    3.  
    4.     If Form3.Text1.Text = "" Or Check1.Value = vbChecked Then
    5.         With CD1
    6.             .DialogTitle = "Open Name File"
    7.             .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    8.             .ShowOpen
    9.             intFileNum = FreeFile
    10.             On Error Resume Next
    11.             Open .FileName For Input As #intFileNum
    12.             While Not EOF(intFileNum)
    13.                 Input #intFileNum, sText$
    14.                 If sText$ = "" Then
    15.                     Exit Sub
    16.                 Else
    17.                     List1.AddItem sText$
    18.                     DoEvents
    19.                 End If
    20.             Wend
    21.             Close #intFileNum
    22.         End With
    23.     End If
    24.    
    25.     Label1.Caption = "Word's: " & List1.ListCount

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