VB project help

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1468 Views - Last Post: 07 April 2013 - 06:35 PM Rate Topic: -----

#16 jbok  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 03-April 13

Re: VB project help

Posted 07 April 2013 - 05:31 PM

This was supposed to be attached to the last post

I got some results with what you told me to do....Thanks...now just have to refine it
Was This Post Helpful? 0
  • +
  • -

#17 jbok  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 03-April 13

Re: VB project help

Posted 07 April 2013 - 05:40 PM

View Postlar3ry, on 07 April 2013 - 05:27 PM, said:

View Postjbok, on 07 April 2013 - 05:07 PM, said:

I found some helpful info in my text book. It's not exactly what what I need but I want to see if it worked and put the first name in the proper place in the list box. Im getting and error stating "make sure arguments have valid values" over the return at the bottom. What would make this a valid value?

Well, I've never had that error show up, but I can see that you don't really have a good grip on the way a Function works. Basically, you pass something to a Function, and assign the returned value to something. You have the call, and it's good. You pass firstname to the Function, and assign its return value to txtName.Text, which is fine.

However, within the Function, you manipulate the string you passed, then return a SubString of txyName.Text, which, while it might work, is not really the way to go about it.

First, you don't need to assign txtNamt.Text to firstname in order to send it to the Function. Your call could be

firstname = NameSplit(txtName.Text)

Then, in the Function (I have renamed the variable to clarify something for you; thatthe variable name within the Function is not a variable name outside the Function)...

    Function NameSplit(ByVal wholename As String) As String
        Dim firstcomma As Integer
        firstcomma = wholename.IndexOf(",")
        Return wholename.Substring(firstcomma + 1)
    End Function


Now, you are passing the complete name as a String. txtName.Text is a String, and in the Function, wholename is also a String (declared in the parameters of the Function), and in addition, it is well worth noting that it is a COPY of the String in txtName.Text (That's what ByVal means.. the value of the argument, rather than the argument itself.

Now all that's left is to return something, and from your variable name, I gather you want that to be the first name, extracted from txtName.Text, You want to return the SubString starting at firstcomma + 1, otherwise you get the comma returned as well.

Give that a try and see if it clears up your error.

Are you using Option Strict On?


Your right, I do not have a full grasp of a function. From what I understand its that same a a button, but I tell it how it should function. And yes my option strict is on

View Postjbok, on 07 April 2013 - 05:31 PM, said:

This was supposed to be attached to the last post

I got some results with what you told me to do....Thanks...now just have to refine it


Ok..it didn't work like I thought it would.

Ill give it a shot la3ry, but I'll have to do it tomorrow. Thank you all for your time
Was This Post Helpful? 0
  • +
  • -

#18 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2264
  • View blog
  • Posts: 9,470
  • Joined: 29-May 08

Re: VB project help

Posted 07 April 2013 - 06:35 PM

Forget about Controls (Buttons Textbox etc) a moment, as they are confusing you more than helping.

Save your project and go create a new Console Application.
This will help a lot, to learn the core types and features of the vb.net programming language, without the distraction of controls.
Forgot about it looking pretty and like professional programs.

You need to understand the basics of the language first.

Have a look through the vb.net Tutorials for tutorials that cover the basics.


Module Module1

  Sub Main()
    Dim x As Integer = 1
    Dim y As Integer = 2
    Dim Z As Integer
    z = Addition( x , y )

  End Sub

  Function Addition ( TakeThis as Integer, AddItToThis As Integer) As Integer
    Return TakeThis + AddItToThis
  End Function

End Module




By using BreakPoints and the Debugger you can see and examine the flow of the program as it executes.

Use the console applications to experiment and try stuff of out. (I Do)
It focuses your design to the essentials parts.

This post has been edited by AdamSpeight2008: 07 April 2013 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2