Visual Basic Coding Help: I have no idea what to do
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Visual Basic Coding Help: I have no idea what to do

  1. #1
    Join Date
    Oct 2013
    Posts
    10

    Visual Basic Coding Help: I have no idea what to do

    I'm suffering from a case of, for lack of a better term, coder's block right. I need to work on this project but I have no idea how to start coding it, other than the immediate obvious.

    The Display button's Click event procedure should read the five numbers stored in the numbers.txt file and display the numbers (one through five) in the list box, and the Update button's Click event procedure should read the same five numbers and store them in an array. It then should increase the numbers in the array by 1 and write the array contents to an empty numbers.txt file.

    Here's what I've got right now:
    Code:
    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Public Class MainForm
    
        Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
            Me.Close()
        End Sub
    
        Private Sub displayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles displayButton.Click
    
        End Sub
    
        Private Sub updateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles updateButton.Click
    
        End Sub
    End Class
    And the list box is named numbersListBox.

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Visual Basic Coding Help: I have no idea what to do

    Firstly... This looks exactly like homework...

    Secondly, Your code has got nothing....

    but here's links on how to do it...

    #1 : open a text file
    #2 : Display data in a listbox
    #3 : adding data to an array
    #4 : Writing to a text file
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Oct 2013
    Posts
    10

    Re: Visual Basic Coding Help: I have no idea what to do

    I could have gotten that very same information from my book, unfortunately it doesn't help in my current situation, considering that it only describes similar projects, and not like the sort of thing I'm looking for.

  4. #4
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    Re: Visual Basic Coding Help: I have no idea what to do

    similar projects is all you need, if you have an example of how to read a file, place data in a list box, add to an array and write to a file then all your requirements are covered except the adding 1 to each value which really should not need to be explained.

    Sure we could write the code for you in a few minutes but that defeats the purpose of the exercise and teaches you nothing.

    You need to do 4 (5) things look at those links and try to write some code. If you run into trouble then post a related question
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Oct 2013
    Posts
    10

    Re: Visual Basic Coding Help: I have no idea what to do

    Here's the updated code.

    Code:
    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Public Class MainForm
    
        Dim loadedfile As String = "d:\test.txt"
        Dim tempstr1 As String = IO.File.ReadAllText(loadedFile)
    
        Private Sub MainForm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Display_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Display.Click
    
            numbersListBox.Items.Add(tempstr1)
    
    
        End Sub
    
        Private Sub update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
            Dim x As Integer = tempstr1.Length - 1
            Dim myarray(x) As String
            Dim i As Integer = 0
            For Each mychr As Char In tempstr1
                myarray(i) = mychr
                i += 1
                ListBox2.Items.Add(i + 1)
    
            Next
    
        End Sub
    End Class
    Last edited by Moon_Dew; October 25th, 2013 at 08:25 PM.

  6. #6
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    Re: Visual Basic Coding Help: I have no idea what to do

    I do not see a question

    I do see that you are adding the whole file to the listbox rather than parsing out the numbers and adding each of them, can't say i have ever tried that to see what the result would be but I would be surprised if it worked.

    not sure what you are trying to do in the loop but it is not close to what you said you wanted

    You assign each char to the array then you add the index+1 to a list box?
    Your OP says that you should add 1 to the values in the array and then write those to a new file.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Visual Basic Coding Help: I have no idea what to do

    loadedfile is erased, isn't it?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    Re: Visual Basic Coding Help: I have no idea what to do

    Quote Originally Posted by dglienna View Post
    loadedfile is erased, isn't it?
    ? why would you think that? There is no code there that writes to or deletes the file. All the text is read into tempstr1 and then he tries to add it all at once to the list box
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Visual Basic Coding Help: I have no idea what to do

    sorry. thought he was reading it again in the sub.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center