Jump to content

Visual Basic Project


TAV1702

Recommended Posts

Fellas, I am in a world of hurt here. I am taking a class on VB and personally I hate it.

I have a project to do that has to do with using constants, functions and sub procedures. It is due by tonight (Tuesday) at 11:59 pm EST

If there is anyone at all who knows VB and would not mind helping me out, I would REALLLLLLLY appreciate it.

The project is all over the net, but the code to me is useless because I do not know if it is right or wrong and if I do not name my buttons and such exactly like they did, the code will not work anyhow.

I am in a real bind here and rarely to never ask for help doing my school work. Taking this course on VB made me realise something REAL fast. I am never going to use it for anything in life. Simply enough, I can not stand VB. I have nothing but respect for those that do like it and are good at it.

Ray

Link to comment
Share on other sites

Oh I never turned it in last night. I got pissed off at it and said the hell with it for the night. I am still trying to get it right. I just suck at VB real bad.

Here is what I am up to.

A fast-food vendor sells:

• pizza slices ($1.75)

• fries ($2.00)

• soft drinks ($1.25)

Write a program to compute a customer’s bill. The program should request the quantity of each item ordered in a Sub procedure, calculate the total cost with a Function procedure, and use a Sub procedure to display an itemized bill.

I have attached the grading rubric as well.

-----------------------------------------------------------------------------------------------------------

Sounds easy enough to most that know how to do it. I am in week 7 of the class and still do not have a clue what I am doing. I have roughed my way through the rest of it thus far. My problem is, instead of using a list box in this project, they want us to use a large text box instead. That makes it much harder for me. A list box I feel a person has more control over.

I still could use a hand if anyone is willing to help. So far all I have done is the GUI and the constants added.

Ray

Link to comment
Share on other sites

Yeah I did google and found a few different sources but the code is all wrong for the grading rubric that I have.

In most of them that are found on line they use a list box where as have to use a large text box. And then some of them are code that people posted and have an error, only to never get help or answer from anyone.

I am literally stuck in a catch 22.

When I do google and they start using big long fancy words and stuff I get lost and just walk away. I do not know why in the hell I had to take this dam class anyhow. To me VB has nothing to do with Network Admin or basic web design or computer forensics even.

Link to comment
Share on other sites

  • Administrators

From what I remember, you'd add three text boxes

Then you can get the value using something like (maybe you know this). The autocomplete/intellisense should help u out when you type the button name and a period:

text1.value
text2.value
text3.value

In the form, add a button in the IDE, then double click onthe button. That should bring u to a code screen, with a function (they call it a sub)

Something like

sub button1_dblclick() 

  calculate_cost(text1.text, text2.text, text3.text)

end sub

' you create a sub (short for subroutine)
' rubric says to create this sub routine
sub calculate_cost(pizza, fries, drink)

do calculations

end sub

I'm rusty on VB, but itll be something like that...I started programming with VB sooo long ago haha

Link to comment
Share on other sites

Nabeel, you are correct. And now the plot thickens. We just got an email from school saying there was a typo in the grading rubric and that we can in fact use a list box. However, I have been working on some code using the large text box.

Here is what I have thus far.

'Pizza Price
Dim PizzaPrice As Double = 1.75
Dim FriesPrice As Double = 2.0
Dim DrinkPrice As Double = 1.75

Private Sub btncompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
Dim pizza As Double
Dim fries As Double
Dim drink As Double
Dim TotalCost As Double

Amount(pizza, fries, drink)
TotalCost = Total_Cost(pizza, drink, fries)
Display(TotalCost, pizza, fries, Drink)

End Sub

Sub Amount(ByRef pizza As Double, ByRef fries As Double, ByRef drink As Double)

pizza = CDbl(FormatNumber(CDbl(txtpizza.Text)))
fries = CDbl(FormatNumber(CDbl(txtfries.Text)))
drink = CDbl(FormatNumber(CDbl(txtdrinks.Text)))

End Sub
Function Total_Cost(ByVal pizza As Double, ByVal Drink As Double, ByVal fries As Double) As Double

'Computing total cost
Return (PizzaPrice * pizza) + (FriesPrice * fries) + (DrinkPrice * Drink)

End Function

I do not think this is correct though. It really needs a catch for each text box to say if a in valid character has been entered. And I am positive I need constants in here as well which I do not have.

Link to comment
Share on other sites

  • Administrators

I used VB 6 last, this seems like it's .NET so the syntax will be a bit different, but the idea the same.

You can use a large textbox just like a list, what you'll do is:

textbox1.text = textbox1.text + "my text" + VbCrLf

Which is taking the current contents of the text box, adding your text, then adding a new line (VbCrLf, a constant). You'll have to enable the multiline property on the text box.

Inside this function:

Private Sub btncompute_Click

You'll want to pull the values from the text boxes for each.

Dim pizza As Double
pizza = PizzaTextBox.Text
If IsNumeric(pizza) == false Then
  /// do something if its not a number?
End If

// do the fries and drink

// You dont need the amount function


// Now calculate the total using the totalcost function
totalCost = TotalCost(pizza, fries, drink)

That will go in that button click function. It'll be something like that... hopefully that makes some better sense?

I'd create a sub to write out to that big text box (let's call it LogTextBox)

Sub WriteToLog(message)
LogTextBox.text = LogTextBox.text + message + VbCrlf
End Sub

So you can do something like:

If IsNumeric(pizza) == false Then
  WriteToLog("Pizza amount is not a number")
  return false
End If

  • Like 1
Link to comment
Share on other sites

Ok I got it!

Once I found out that I was able to use a list view after all instead of having to use a large text box, I opened up the original project that I started and worked on it for a few minutes and tah dah! She works!

Originally, I had the project done once and it worked. We then got told that if we used a listbox it would be incorrect so I scrapped the project and started from scratch. Here is the final results in all her glory FINALLY working the right way.

Link to comment
Share on other sites

I used VB 6 last, this seems like it's .NET so the syntax will be a bit different, but the idea the same.

You can use a large textbox just like a list, what you'll do is:

textbox1.text = textbox1.text + "my text" + VbCrLf

Which is taking the current contents of the text box, adding your text, then adding a new line (VbCrLf, a constant). You'll have to enable the multiline property on the text box.

Inside this function:

Private Sub btncompute_Click

You'll want to pull the values from the text boxes for each.

Dim pizza As Double
pizza = PizzaTextBox.Text
If IsNumeric(pizza) == false Then
  /// do something if its not a number?
End If

// do the fries and drink

// You dont need the amount function


// Now calculate the total using the totalcost function
totalCost = TotalCost(pizza, fries, drink)

That will go in that button click function. It'll be something like that... hopefully that makes some better sense?

I'd create a sub to write out to that big text box (let's call it LogTextBox)

Sub WriteToLog(message)
LogTextBox.text = LogTextBox.text + message + VbCrlf
End Sub

So you can do something like:

If IsNumeric(pizza) == false Then
  WriteToLog("Pizza amount is not a number")
  return false
End If

Even though I got my original one back out and working, it is good to go. However, the whole large text box thing and not working really had me P*ssed off very bad. I am going to work on it for the hell of it and try what you have suggested here to see if I can get it to work.

And you are correct. It is VB.Net I am using 2008 Express.

Link to comment
Share on other sites

Another thing that was shafting me was the original Doubles in my 3 text boxes that I was using. Since doubles use decimals, Double would not have worked here so they needed to be Integers. The double came in to play during the whole calculate cost deal due to the fact that decimals were going to be used.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...