PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Keep getting this error at the end. :( :(-VBForums
Results 1 to 11 of 11

Thread: Keep getting this error at the end. :( :(

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    13

    Keep getting this error at the end. :( :(

    Code:
    Module Module1
        Structure MembershipInformation
            Dim membership_ID As String
            Dim name As String
            Dim email_address As String
            Dim month_joined As String
            Dim MonthlyFeesPayed As String
            Dim membership_active As Boolean
        End Structure
        Sub Main()
            Dim Info(10) As MembershipInformation
            'Inputs
            For index = 1 To 2
                Do
                    Console.WriteLine("Enter '3 digit' membership ID: ")
                    Info(index).membership_ID = Console.ReadLine()
                    If Info(index).membership_ID.Length < 0 Or Info(index).membership_ID.Length > 4 Then
                        Console.WriteLine("Invalid membership ID, Please try again.")
                    End If
                Loop Until Info(index).membership_ID.Length = 3
    
                Console.WriteLine("Enter name: ")
                Info(index).name = Console.ReadLine()
    
                Console.WriteLine("Enter email address: ")
                Info(index).email_address = Console.ReadLine()
    
                Console.WriteLine("Enter month joined (full name of month in words): ")
                Info(index).month_joined = Console.ReadLine()
    
                Console.WriteLine("Is monthly fees payed?")
                Dim MonthlyFeesAnswers() As String = {"Yes", "yes", "YES"}
                Info(index).MonthlyFeesPayed = Console.ReadLine()
                If MonthlyFeesAnswers.Contains(Info(index).MonthlyFeesPayed) Then
                    Info(index).membership_active = True
                Else
                    Info(index).membership_active = False
                End If
            Next
            'TextFile
            FileOpen(1, "D:\TextFile.txt", OpenMode.Output) 'Writing to text file'
            FilePut(1, Info)
            FileClose(1)
    
        End Sub
    
    End Module
    ** Errror at FilePut(1, Info). It keeps saying 'bad file mode'

    Can someone help ASAP please.
    Last edited by Shaggy Hiker; Jun 19th, 2019 at 08:33 AM. Reason: Added CODE tags.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,015

    Re: Keep getting this error at the end. :( :(

    Please don't post unformatted code. It's too hard to read.
    vb.net Code:
    1. Module Module1
    2.     Structure MembershipInformation
    3.         Dim membership_ID As String
    4.         Dim name As String
    5.         Dim email_address As String
    6.         Dim month_joined As String
    7.         Dim MonthlyFeesPayed As String
    8.         Dim membership_active As Boolean
    9.     End Structure
    10.     Sub Main()
    11.         Dim Info(10) As MembershipInformation
    12.         'Inputs
    13.         For index = 1 To 2
    14.             Do
    15.                 Console.WriteLine("Enter '3 digit' membership ID: ")
    16.                 Info(index).membership_ID = Console.ReadLine()
    17.                 If Info(index).membership_ID.Length < 0 Or Info(index).membership_ID.Length > 4 Then
    18.                     Console.WriteLine("Invalid membership ID, Please try again.")
    19.                 End If
    20.             Loop Until Info(index).membership_ID.Length = 3
    21.  
    22.             Console.WriteLine("Enter name: ")
    23.             Info(index).name = Console.ReadLine()
    24.  
    25.             Console.WriteLine("Enter email address: ")
    26.             Info(index).email_address = Console.ReadLine()
    27.  
    28.             Console.WriteLine("Enter month joined (full name of month in words): ")
    29.             Info(index).month_joined = Console.ReadLine()
    30.  
    31.             Console.WriteLine("Is monthly fees payed?")
    32.             Dim MonthlyFeesAnswers() As String = {"Yes", "yes", "YES"}
    33.             Info(index).MonthlyFeesPayed = Console.ReadLine()
    34.             If MonthlyFeesAnswers.Contains(Info(index).MonthlyFeesPayed) Then
    35.                 Info(index).membership_active = True
    36.             Else
    37.                 Info(index).membership_active = False
    38.             End If
    39.         Next
    40.         'TextFile
    41.         FileOpen(1, "D:\TextFile.txt", OpenMode.Output) 'Writing to text file'
    42.         FilePut(1, Info)
    43.         FileClose(1)
    44.  
    45.     End Sub
    46.  
    47. End Module

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,015

    Re: Keep getting this error at the end. :( :(

    As for the issue, you shouldn't be using that style of I/O in the first place. If you're using VB.NET then you should use it, rather than writing VB6 I/O code. If you want to write to a text file then either create a StreamWriter and write as required or call File.WriteAllText to write the entire contents in one go, creating or overwriting the file as required.
    Last edited by jmcilhinney; Jun 19th, 2019 at 06:11 PM.

  4. #4
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,177

    Re: Keep getting this error at the end. :( :(

    As for your slightly different question on a different thread on how to write out your data to a single line of a text file, I would look at the StringBuilder class. Loop through your Info array, creating the desired string and then write it to StreamWriter. That would look roughly like this
    Code:
    Dim sb As New Text.StringBuilder
    For index = 1 To 2
        sb = sb.Append(Info(index).membership_ID & "," & Info(index).name & "," & Info(index).email_address & "," & Info(index).month_joined & "," & Info(index).MonthlyFeesPayed & "," & Info(index).membership_active & ",")
    Next
    Dim streamW As New IO.StreamWriter("D:\TextFile.txt")
    streamW.WriteLine(sb.ToString)
    streamW.Flush()
    streamW.Close()
    There may be a nicer way to do the concatenation. If you had a String array (or List of String) rather than a Structure you could use the Join method. I think that would miss the delimiter between records whereas the code above leaves an extra comma at the last record that you could not insert easily enough.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    13

    Re: Keep getting this error at the end. :( :(

    Thanks.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    13

    Re: Keep getting this error at the end. :( :(

    Thanks a lot for this.

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,450

    Re: Keep getting this error at the end. :( :(

    As for you original problem, it would seem to indicate perhaps you aren't that familiar with VB6 to begin with, so using legacy VB I/O is doubly wrong.
    You use Put for Binary and Random access files in VB6, you would use Write or Print for a file opened for Output.

    Info not to be taken as any encouragement to use legacy VB I/O methods in .Net.

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    13

    Re: Keep getting this error at the end. :( :(

    Sorry to bother, but what If I wanted the format in the text file to look like this:

    MemID name email address month joined membership status
    001: John J@yahoo.com april Active
    002: . . . ... .. . .. . . .. . .. . . .. . . .. . .. . . . . . .. . . . .. . . . . .

    and so on,
    Do you get what I mean?

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    13

    Re: Keep getting this error at the end. :( :(

    Sorry to bother, but what If I wanted the format in the text file to look like this:

    MemID name email address month joined membership status
    001: John april Active
    002: . . . ... .. . .. . . .. . .. . . .. . . .. . .. . . . . . .. . . . .. . . . . .

    and so on,
    Do you get what I mean?

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    13

    Re: Keep getting this error at the end. :( :(

    Forget the format I just said. Sorry..
    I would actually need it to be display like this in the text file:

    MemID: ...
    Name: ...
    email address: ... ..
    Month joined: ...
    Membership status: ... .
    -----------------------------
    MemID: ...
    Name: ...........
    email address: ... ..
    Month joined: ...
    Membership status: ... .

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,015

    Re: Keep getting this error at the end. :( :(

    You can write whatever you want to the file using a StreamWriter. Read about the class, check out some existing examples, try to do what you want to do and then post if and when you encounter an actual issue.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width