Jump to content

Welcome to TheHotfix.net Forums

Welcome to TheHotfix.net Forums, like most online communities you must register to view or post in our community, but don't worry this is a simple free process that requires minimal information for you to signup. Be apart of TheHotfix.net Forums by signing in or creating an account.
  • Start new topics and reply to others
  • Subscribe to topics and forums to get automatic updates
  • Get your own profile and make new friends
  • Customize your experience here
Guest Message by DevFuse
 

Photo

VB Script Help


  • Please log in to reply
51 replies to this topic

#1 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 01 October 2009 - 05:16 PM

Can anyone give me the VB Script code for making a price entry box with 2 buttons, the buttons should be (+VAT @ 17.5%) and (-VAT @ 17.5%) - When the buttons are pressed it should calculate the new total in either the price entry box or in a separate box?

Thanks coders !!
  • 0

#2 MrDan

MrDan

    TROLOLOLOLOLOLOL!

  • Administrator
  • 3530 posts
  • Gender: Male
  • Location: Ye old'e Anglia!
  • Country:
  • Interests: Computers, football (Chelsea FC).

Posted 01 October 2009 - 05:19 PM

it's 15% VAT ;) :whistle:
  • 0

#3 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 01 October 2009 - 05:23 PM

I know but its going back up soon, so ......

Anyway, if I get the script I can change it :)
  • 0

#4 Scott

Scott

    Lost

  • Ultimate Sponsor
  • 860 posts
  • Gender: Male
  • Location: Louisville Ky
  • Country:

Posted 01 October 2009 - 06:05 PM

is that your tax
  • 0

#5 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 01 October 2009 - 06:13 PM

Yea thats how much tax we have to pay and charge on goods

Its 15% for now - but always used to be 17.5% and will be back up there soon
  • 0

#6 Scott

Scott

    Lost

  • Ultimate Sponsor
  • 860 posts
  • Gender: Male
  • Location: Louisville Ky
  • Country:

Posted 01 October 2009 - 06:18 PM

we pay 6% here and the the town i live in puts an extra 1% on that. we just started paying taxes on alcohol not to long ago.
  • 0

#7 formula_86

formula_86

    I'm The Hitman! xD

  • Exclusive Member
  • 1278 posts
  • Gender: Male
  • Location: London, United Kingdom
  • Country:
  • Interests: Someone to call a friend :)

Posted 01 October 2009 - 07:39 PM

Off-Topic

Just out of intrest, are you going to be using the price entry thingy if someone finds code for it for the place you work at? :rolleyes: :whistle:
  • 0

#8 Diablofan

Diablofan

    Retired Lazy (at times) Staff Member

  • VIP
  • 2033 posts
  • Gender: Male
  • Location: Ohio
  • Country:
  • Interests: Building/Fixing Computers, Programming, Video Games, Camping, Anime, Manga

Posted 01 October 2009 - 09:34 PM

I think I might be able to help with your VB Script problem. I know VB so I should be able to help you out...but not right now, I'm at school while I'm typing this.
  • 0

#9 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 01 October 2009 - 09:37 PM

Thanks Diablo that would be good thanks
  • 0

#10 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 04 October 2009 - 09:44 PM

Spooks go "BUMP" in the night!!
  • 0

#11 7dude

7dude

    The Hotfix Lead Developer

  • VIP
  • 1512 posts
  • Gender: Male
  • Country:

Posted 05 October 2009 - 12:00 AM

Dave - go download Visual Studio Express from Microsoft, set the project VB, then do this...

1) Use the default window that appears, drag it to fit your size
2) Use the toolbox to create all the input fields and buttons you want.
3) Name your input fields accordingly.
4) Double Click the button next to the input field for the % u want to control, and type:
int price;
int vat = .15; 
int total;
price = input_field_name->value;
total = price*vat;

total_price_input_field_name->value = total;

5) Repeat step 4 for all the other other input field/button combinations you want.


I haven't touched VB for a REALLY long time, but Line 4 & 7 should work. If not, I'm sure Diablo can correct my syntax.

Dave - why not make a web program for this? That way it can be mobile and you don't have to have any other VB dependencies, plus it is multi-OS. I can help you with a Web version of this, if you are interested. ;)
  • 0

#12 Diablofan

Diablofan

    Retired Lazy (at times) Staff Member

  • VIP
  • 2033 posts
  • Gender: Male
  • Location: Ohio
  • Country:
  • Interests: Building/Fixing Computers, Programming, Video Games, Camping, Anime, Manga

Posted 05 October 2009 - 03:39 AM

Dave - go download Visual Studio Express from Microsoft, set the project VB, then do this...

1) Use the default window that appears, drag it to fit your size
2) Use the toolbox to create all the input fields and buttons you want.
3) Name your input fields accordingly.
4) Double Click the button next to the input field for the % u want to control, and type:

int price;
int vat = .15; 
int total;
price = input_field_name->value;
total = price*vat;

total_price_input_field_name->value = total;

5) Repeat step 4 for all the other other input field/button combinations you want.


I haven't touched VB for a REALLY long time, but Line 4 & 7 should work. If not, I'm sure Diablo can correct my syntax.

Dave - why not make a web program for this? That way it can be mobile and you don't have to have any other VB dependencies, plus it is multi-OS. I can help you with a Web version of this, if you are interested. ;)

Your code is completely wrong ben. Right idea, wrong syntax though. It should be
Dim price as double
Dim vat as float = .15
Dim total as float
price = cdbl(input_field_name.text)
total = price*vat

total_price_input_field_name.text = "$" & total
I also agree with you ben, he should make it make it a web version. Unless he only plans to run this on like 1 computer, then it would be a waste.
  • 0

#13 7dude

7dude

    The Hotfix Lead Developer

  • VIP
  • 1512 posts
  • Gender: Male
  • Country:

Posted 05 October 2009 - 10:53 PM

With jQuery, Dave, this would work:
function calcVat()
{
 var price = $("#price").val();
 var total = "$"+price*.15;
 $("#input1").val(total);
}


that would be the function for the onpress for the button. I'll make the entire program for you if you want.
  • 0

#14 7dude

7dude

    The Hotfix Lead Developer

  • VIP
  • 1512 posts
  • Gender: Male
  • Country:

Posted 06 October 2009 - 01:15 AM

Your code is completely wrong ben. Right idea, wrong syntax though. It should be

Dim price as double
Dim vat as float = .15
Dim total as float
price = cdbl(input_field_name.text)
total = price*vat

total_price_input_field_name.text = "{:content:}quot; & total
I also agree with you ben, he should make it make it a web version. Unless he only plans to run this on like 1 computer, then it would be a waste.


OOH! I see now, I was remembering C++. Yeah...ok.. You're right. I don't/never liked VB, I always thought it was inferior. Haha!
  • 0

#15 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 06 October 2009 - 06:31 AM

Hey Guys thanks alot for this, I will try VB first and yea a web based one would be cool too

Thanks for the help, If I manage to make this easily, I might donate some of my life to learning VB !!

Thanks again!
  • 0

#16 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 06 October 2009 - 11:01 AM

With jQuery, Dave, this would work:

function calcVat()
{
 var price = $("#price").val();
 var total = "{:content:}quot;+price*.15;
 $("#input1").val(total);
}


that would be the function for the onpress for the button. I'll make the entire program for you if you want.


Im trying it myself too but yea that would be good if you made one too coz I cant see mine working lmao



Ok Im guessing I am supposed to change some code here?? To what, remember I am less than a newbie when it comes to programming

Posted Image

Edited by Dave, 06 October 2009 - 11:07 AM.

  • 0

#17 Diablofan

Diablofan

    Retired Lazy (at times) Staff Member

  • VIP
  • 2033 posts
  • Gender: Male
  • Location: Ohio
  • Country:
  • Interests: Building/Fixing Computers, Programming, Video Games, Camping, Anime, Manga

Posted 06 October 2009 - 02:35 PM

Im trying it myself too but yea that would be good if you made one too coz I cant see mine working lmao



Ok Im guessing I am supposed to change some code here?? To what, remember I am less than a newbie when it comes to programming

Posted Image

Aw crap, I was remembering a bit of C++ as well. Those 'float's should be Decimals. Input field name needs to be the name of the text box where you enter the price. The total_price_input_field_name should be the name of the text box of where the price gets printed into.

OOH! I see now, I was remembering C++. Yeah...ok.. You're right. I don't/never liked VB, I always thought it was inferior. Haha!

I agree with you. C++ is way more superior to Any .NET Language and Java. Mainly because of the sheer amount of control you have over the language and how it operates.
  • 0

#18 Dave

Dave

    Zero Tolerance

  • Administrator
  • 11567 posts
  • Gender: Male
  • Location: UK
  • Country:

Posted 06 October 2009 - 09:50 PM

So I change "float" to "decimal" ?

and the name of the text box where I enter the price can be anything I choose ?

and the same with the total_price_input_field_name... it can be whatever I choose ?

Is this right ?

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

Dim price as double
Dim vat as decimal = .15
Dim total as decimal
price = cdbl(anything_I_like.text)
total = price*vat

anything_I_like.text = "{:content:}quot; & total

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


Edited by Dave, 06 October 2009 - 09:52 PM.

  • 0

#19 someone64

someone64

    TheHotfix Addicted

  • Exclusive Member
  • 693 posts
  • Gender: Not Telling
  • Country:

Posted 06 October 2009 - 11:06 PM

Try making something like this:

Posted Image

And try this code:
__________

Public Class Form1
Dim price As Decimal
Dim vat As Decimal = 0.175
Dim total As Decimal
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = price
Call totalPrice()
TextBox2.Text = total
End Sub
Public Sub totalPrice()
If RadioButton1.Checked = True Then
total = 'put formula to calculate +VAT @ 17.5%
Else : total = ' put formula to calculate -VAT @ 17.5%
End If
End Sub
End Class
__________

I think that should work, but I don't know what exactly the VAT buttons should calculate, so I've left that area commented so you can make your own formula.

Edited by someone64, 06 October 2009 - 11:10 PM.

  • 1

#20 7dude

7dude

    The Hotfix Lead Developer

  • VIP
  • 1512 posts
  • Gender: Male
  • Country:

Posted 06 October 2009 - 11:37 PM

Dave:

I've made a really quick and simple version of this that will work on any computer with an Internet connection (it uses jQuery which is hosted on Google.)

If you want to, I will make you a version that will work by itself with no Internet connection. Just say the words.

Here's the code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
 //******************* DAVE: Edit params here. *******************//
 
 var vat = .15; // Percentage in decimal form, please.
 
 //******************* DAVE: Don't touch anything after this. *****************//
 $(document).ready(function() {

 var vat_p = vat*100;
 $("#submit").val("Calculate with VAT at "+vat_p+"%");
 });

function calcVat()
{
 var price1, price1_vat, price1_total;
 price1 = $("#price1").val(); // Get Price1 Value
 price1_vat = price1*vat; // Get the VAT Tax for that price
 price1_total = parseFloat(price1_vat)+parseFloat(price1);
 if(isNaN(price1_total))
 alert("Please enter a valid number.");
 else
 $("#total1").val(price1_total); // Write the total into input box.
}
 
</script>
<html>
 <form name="vatPricer">
 <label for="price1">Price:</label>
 <input type="text" id="price1" name="price1" /> 
 <input type="button" id="submit" value='Loading...' onclick="javascript:calcVat();" name="submit">
 


 <label for="total1">Price after VAT:</label>
 <input type="text" readonly="readonly" id="total1" name="total1" />
 </form>
</html>

I could make it much prettier with some CSS, but that's it. If you want me to create two separate buttons that are +VAT and -VAT, tell me as well.

Here's the actual HTML file.
Attached File  dave.html   1.21K   6 downloads

To run it, just open it in the browser of your choice.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users