The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Visual basic help

override367override367 ALL minionsRegistered User regular
edited May 2010 in Help / Advice Forum
I've only used VB a few times before and am totally in the dark as how to do what I'm being asked to do for this part of the assignment

Much googling hasn't helped

I have a text file with a series of numbers, each series seperated by zeros


eg:

1
2
3
0
1
2
3

I need my application to read the text file and store each number in an array. There's a bunch of other stuff too, but I got how to do all of that, I don't know how to get it to look in a file and pull numbers out, or put them in arrays, or to differentiate between series

Really wish I hadn't sold my textbooks but, the book store only needed 2 more and offered a good price

override367 on

Posts

  • foggratfoggrat Registered User regular
    edited May 2010
    Well, to start with, you'll want to use the FileSystem Object to read each line. Here's a link that talks about that:

    http://support.microsoft.com/kb/186118

    To stuff things in arrays, here's a link:

    http://patorjk.com/programming/tutorials/vbarrays.htm

    Since you don't know how large the array will be until you stuff it, I think "Dynamic Arrays" may be particularly useful.

    Hope these resources help!

    foggrat on
  • bowenbowen Sup? Registered User regular
    edited May 2010
    Are you having trouble with the code, or the logic?

    Also, VB6 or VB.NET?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • override367override367 ALL minions Registered User regular
    edited May 2010
    foggrat wrote: »
    Well, to start with, you'll want to use the FileSystem Object to read each line. Here's a link that talks about that:

    http://support.microsoft.com/kb/186118

    To stuff things in arrays, here's a link:

    http://patorjk.com/programming/tutorials/vbarrays.htm

    Since you don't know how large the array will be until you stuff it, I think "Dynamic Arrays" may be particularly useful.

    Hope these resources help!

    Thanks I'm gonna read these over

    I mean it seems like it's way too complicated and I'm over thinking it, given that the next hardest assignment I've done consists entirely of this
    Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalculate.Click
    ' First it sets the variable we're going to use, then clears the listbox from previous usage
    A = Val(TxtInputbox.Text)
    LstListbox.Items.Clear()
    ' Checks if the value of the textbox is less than 100 before doing anything, if it is then we display
    ' an error message
    If Val(TxtInputbox.Text) < 100 Then
    LblWarningLabel.Show()
    LstListbox.Items.Add(B)
    ' Checks if the value is over or equal to 100 and if it is hide previous warnings...
    ElseIf Val(TxtInputbox.Text) >= 100 Then
    LblWarningLabel.Hide()
    ' ... and start the loop, adding items to the listbox until the variable is ten less than the textbox
    Do
    LstListbox.Items.Add(A - 1)
    A = A - 1
    Loop Until (A = Val(TxtInputbox.Text) - 10)
    End If

    End Sub
    And took like, 15 minutes

    It's VB.net btw

    Edit: i think that first link is only applicable for vb6

    override367 on
  • bowenbowen Sup? Registered User regular
    edited May 2010
    StreamReader is what you're looking for in .NET.

    http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx
    Imports System
    Imports System.IO
    
    Class Test
        Public Shared Sub Main()
            Try
                ' Create an instance of StreamReader to read from a file.
                Dim sr As StreamReader = New StreamReader("TestFile.txt")
                Dim line As String
                ' Read and display the lines from the file until the end 
                ' of the file is reached.
                Do
                    line = sr.ReadLine()
                    Console.WriteLine(Line)
                Loop Until line Is Nothing
                sr.Close()
            Catch E As Exception
                ' Let the user know what went wrong.
                Console.WriteLine("The file could not be read:")
                Console.WriteLine(E.Message)
            End Try
        End Sub
    End Class
    
    
    

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • override367override367 ALL minions Registered User regular
    edited May 2010
    Oh god he's got an example VB project on blackboard hidden away, my friend just e-mailed me lol

    we've only been on VB for 2 weeks and I have zero prior experience

    yea streamreader is what hes doing, should be able to get it between the example and your link bowen thanks

    override367 on
  • ChickeenChickeen Registered User regular
    edited May 2010
    Dim asdf() As String = System.IO.File.ReadAllLines("c:\temp\test.txt")

    Chickeen on
Sign In or Register to comment.