Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

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


  • Please log in to reply

#1
Moon_Dew

Moon_Dew

    Member

  • Member
  • PipPip
  • 10 posts
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:
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.
  • 0

Advertisements


#2
Moon_Dew

Moon_Dew

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts
Bump
  • 0

#3
PhrantiQ

PhrantiQ

    Member

  • Member
  • PipPipPip
  • 399 posts
Though I am not one to give out code per say, I could give you some 'leads' on it and have a few questions. 
How are these numbers stored in the text file? Also you state the numbers.txt file as the open and save name - Are you over writing it or dropping it somewhere else? Either way, what you'll want to do would be as follows...

Have the code read the files text into memory. Have it then sort the numbers out (for instance having a , or : or etc between them) into the values for list box line values. Then you will want to do just like you said, or you could have list box line 1's value be put to a temporary string and have a mathematical run through that grabs that string and adds numerical value of 1 to it. Then you set this process to go through all available lines in the list box. Then you have all these values to be written to a file of your choosing, separating them as you need or what not.

If you need more precise things or want me to review anything further after you code it just post it up.

  • 0

#4
Moon_Dew

Moon_Dew

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts
Here's the new updated 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

I had some help with this one, unfortunately I neglected to mention that I can only use one list box, and that the numbers in that one list box are the same ones that need to be updated by one when I click the update button.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP