Visual Basic 2008

Rachkir

2008-11-04 20:00:33

um, I know this isnt a very good place for this subject, but I know a lot of you are smart with computer languages. It did say software development under description....

FOR THE RECORD, MSDN FORUMS ARE A PEICE OF SHIT AND SO IS MSDN LIBRARY AND SO IS THIS SOFTWARE LANGUAGE AND SO IS USING INPUT BOXES FOR DATA

heres my code, well, not what I want, this is simple test code trying to get shit to work right.

' double variables to store values entered in input boxes
Dim dblHours, dblPayRate, dblState, dblFed, dblFICA As Double
dblHours = InputBox("Please Enter Hours Worked")
dblPayRate = InputBox("Please Enter Rate of Pay")
dblState = InputBox("Enter Percent of State Income Tax to Withhold")
dblFed = InputBox("Enter Percent of Federal Income Tax to Withhold")
dblFICA = InputBox("Enter Percent of FICA Income Tax to Withhold")


Dim dblGrossPay, dblNetPay, dblPercentState, dblPercentFed, _
dblPercentFICA As Double
Dim strPercentState, strPercentFed, strPercentFICA As String

' data conversions to change value stored from input box into a percentage
strPercentState = dblState.ToString("p")
strPercentFed = dblFed.ToString("P")
strPercentFICA = dblFICA.ToString("p")

' Main Computation
dblGrossPay = CDbl(dblHours * dblPayRate)
dblPercentState = CDbl(dblGrossPay * strPercentState)
dblPercentFed = CDbl(dblGrossPay * strPercentFed)
dblPercentFICA = CDbl(dblGrossPay * strPercentFICA)
dblNetPay = CDbl(dblGrossPay - dblPercentFed _
- dblPercentState - dblPercentFICA)

I keep getting errors stating the string cannot convert to data type double, mind you this says it regardless of the data type variable used to store the math. it stops on the 2nd line of math : dblPercentState = CDbl(dblGrossPay * strPercentState)

I havent found a way to convert the value stored from the InputBox to a percentage unless I use the .ToString method. which is annoying becuase it only works sending a value to a string. And I really dont want to use double data types for my InputBox variables because then I cannot test for empty string input.

Of course this is lacking the code to display the data on the design form. Its going to on in a list box because my assignment tells me to. I shouldve picked the easier one....but then you dont learn anything. I need to do this for 4 employees and figure out how to show 4 employees data in one list box. Not to hard considering Ive done showed information in list boxes, making it look like excel spreadsheets. Pain in da butt.
Ive tried many ways, and my book is a peice of shit and my teacher does not respond.

Keeper

2008-11-04 20:19:29

You are trying to multiply a double to a string then convert it to a double:

Code: Select all

dblPercentState = CDbl(dblGrossPay * strPercentState)
dblPercentFed = CDbl(dblGrossPay * strPercentFed)
dblPercentFICA = CDbl(dblGrossPay * strPercentFICA)
Should be:

Code: Select all

dblPercentState = dblGrossPay * CDbl(strPercentState)
dblPercentFed = dblGrossPay * CDbl(strPercentFed)
dblPercentFICA = dblGrossPay * CDbl(strPercentFICA)
I don't have VB fired up ( I rarely use it ), but can't something like this work too?

Code: Select all

dblPercentState = dblGrossPay * strPercentState.ToDouble()
dblPercentFed = dblGrossPay * strPercentFed.ToDouble()
dblPercentFICA = dblGrossPay * strPercentFICA.ToDouble()

Rachkir

2008-11-04 20:29:31

Negative.

Your first example gives me the same run time error
The 2nd example will not work because there is no .ToDouble method at least for the string data type

You did however give me some ideas though, there are usually a few ways to work around something in the language. Many thanks for the prompt reply Keeper.

Keeper

2008-11-04 21:17:20

Ok

I just looked at your code.

Why are you converting from dbl to string ( as a percentage ) only to want it back to a double?

Why not just divide the response by 100?

Code: Select all

dblPercentState = dblGrossPay * dblState / 100

Rachkir

2008-11-04 21:37:02

oh damn. Yeah, I never thought of that. Geez, I always miss the obvious. I just seen in my text that you can have values automatically converted to a percentage, so I was trying to use that method, but apparently it's just not going to work here because Ive exhausted many different ways of writing that code.

I feel confident that will work, well, because it will. Gosh I feel silly now. Ty keeper. You just saved my ass, this is due today by midnight. And now I can use my exception handling and validating input code. Horray for Keeper.

The main reason I was using a string variable for my input box was so I could test for an empty string, if the user did not input anything. But I'm starting to wonder if you can use the = string.empty method for any data type variable...never tried it on anything but a string variable. This way I can avoid run-time errors when theres no data input. To use the .ToString method, the value must go into a string, and this was also the only way I knew of to automatically convert a value to percentage form, example : strNumber = dblWassup.tostring("p") the ("P") being the attribute to convert to percentage.

In the first post of my code, I used doubles for the variable for the inputbox, because my text had the example of stringvariable = doublevariable.tostring("P") but in reality I want to use string variables for inputbox....now I can. because I will use math to get the percentage. duh.

The assignments in this class do not require Exception Handling, but everyone assignment I do I try to incorparate as much as I can because I know in the real world of programing, this are just not this simple.

Outta curiosity, what languages do you typically work with? And is there any place you recommend for beginner developers to post when issues like this arise? As I stated before, MSDN forums = fail.

Rachkir

2008-11-04 21:50:13

damn I'm happy. :lol:

knew this was a good idea posting it here.

Edge

2008-11-11 00:48:33

Just for future reference in vb any numbers that you need hell ne thing you need converted from a string is pretty easy.

Example:

dim dblnum as double
dim dblstr as string = "1.00"

dblnum = double.parse(dblstr)

dim intnum as integer
dim intstr as string = "1"

intnum = integer.parse(intstr)

dim ipadd as system.net.ipaddress
dim ipstr as string = "127.0.0.1"
ipadd = system.net.ipaddress.parse(ipstr)

so on and so forth.

I work with VB.Net often and I do a bit with other languages too.

0nti

2008-11-11 23:01:52

I will eventually learn all this...just wait for me about 5 years hahahaha :lol:

badinfluence

2008-11-12 02:25:41

It's ok onti. I don't have a clue what they are talking about.

Edge

2008-11-12 05:18:45

badinfluence wrote:It's ok onti. I don't have a clue what they are talking about.
I'll comment it out next time :D