Werne Posted November 23, 2012 Share Posted November 23, 2012 Before I say anything else I have to say that I don't know much about scripting (I know just a little bit). It always drew me nuts so I avoided it. And now I need help with a script I made. Actually, it's more of an answer to the question in the title. Anyway, after aproximately 20 mins of reading on VBScripts (had no prior knowledge of any scripting language) and 3 hours of playing around Notepad++, I managed to write this: Dim WerneVs, WerneVl, WerneI, WerneN, Wernetot, Wernetot2, Wernetot3 MsgBox ("Welcome to Werne's LED Calculator, press enter to continue.") MsgBox ("Common LED diode voltages:" & vbNewLine & "IR - 1.5V" & vbNewLine & "Red - 2.0V" & vbNewLine & "Orange - 2.0V" & vbNewLine & "Yellow - 2.1V" & vbNewLine & "Green - 2.2V" & vbNewLine & "Real Green - 3.3V" & vbNewLine & "Blue - 3.3V" & vbNewLine & "White - 3.3V" & vbNewLine & "UV - 3.3V" & vbNewLine & "Blue (430 nm) - 4.6V") WernePerc=60 WernePerc2=100 WerneV=10 WerneMA=1000 WerneVs=InputBox ("Input source voltage multiplied by 10:") WerneVl=InputBox ("Input LED voltage multiplied by 10:") WerneI=InputBox ("Input LED current in mA:") WerneN=InputBox ("Number of diodes:") intAnswer=_ MsgBox ("Is this a parallel connection? Click yes if there is only one diode", vbYesNo) If intAnswer= vbYes Then Wernetot=((cint(WerneVs)/cint(WerneV))-(cint(WerneVl)/cint(WerneV)))/((cint(WerneI)*cint(WerneN))/cint(WerneMA)) MsgBox ("Resistor Value:") & vbNewLine & Wernetot Wernetot2=((cint(WerneVs)/cint(WerneV))-(cint(WerneVl)/cint(WerneV)))*((cint(WerneI)*cint(WerneN))/cint(WerneMA)) MsgBox ("Resistor Wattage:") & vbNewLine & Wernetot2 Wernetot3=((((cint(WerneVs)/cint(WerneV))-(cint(WerneVl)/cint(WerneV)))*((cint(WerneI)*cint(WerneN))/cint(WerneMA)))/(cint(WernePerc)))*cint(WernePerc2) MsgBox ("Safe-to-use Resistor Power Rating:") & vbNewLine & Wernetot3 Else Wernetot4=((cint(WerneVs)/cint(WerneV))-((cint(WerneVl)*cint(WerneN))/cint(WerneV)))/(cint(WerneI)/cint(WerneMA)) MsgBox ("Resistor Value:") & vbNewLine & Wernetot4 Wernetot5=((cint(WerneVs)/cint(WerneV))-((cint(WerneVl)*cint(WerneN))/cint(WerneV)))*(cint(WerneI)/cint(WerneMA)) MsgBox ("Resistor Wattage:") & vbNewLine & Wernetot5 Wernetot6=((((cint(WerneVs)/cint(WerneV))-((cint(WerneVl)*cint(WerneN))/cint(WerneV)))*(cint(WerneI)/cint(WerneMA)))/(cint(WernePerc)))*cint(WernePerc2) MsgBox ("Safe-to-use Resistor Power Rating:") & vbNewLine & Wernetot6 end if I have no freakin' idea how I managed to make it but surprisingly, it works great. It's sort of a calculator but it's sole purpose is to calculate what kind of a resistor is needed for an LED diode (wattage, resistance, etc.). Problem is, the formula for calculating that is R = (Vs - Vl) / I. If Vs = 5.4V, Vl = 3.3V and I = 0.02A then it's (5.4 - 3.3) / 0.02 = 105ohm But in VBS it's (5 - 3) / 0 = Error: Division by zero :facepalm: Since I have no idea how to make it work like I want, I made some modifications to get around the problem and still get the right result (it drove me nuts :wallbash:). So, Is it possible to somehow make the end result of that script to accept numbers in decimal form so I don't have to do stupid stuff just to get what I need? All help is appreciated :thumbsup: Link to comment Share on other sites More sharing options...
flamenx01 Posted November 23, 2012 Share Posted November 23, 2012 try putting WernePerc=60 WernePerc2=100 WerneV=10 WerneMA=1000 as WernePerc=60.0 WernePerc2=100.0 WerneV=10.0 WerneMA=1000.0 that might work but I'm not 100% sure as I've never done VBScript Link to comment Share on other sites More sharing options...
Vagrant0 Posted November 23, 2012 Share Posted November 23, 2012 Integers cannot store anything as decimal... being that they are integers. If you're using integers, and cannot use floats or another data format that allows for decimals, you pretty much need to store the whole number as an integer, and then translate the value somehow in a way that reads as a decimal by either inserting a period somewhere in a string that is used as the output, or by pruning off that portion that would normally be a decimal and saving it as a separate integer which would be used in a way that would display as a decimal. In almost every case, you're pretty much better off just storing these values as floats or some memory type that natively supports decimal use (unless you somehow like the idea of multiplying everything by 1,000,000,000,000 before dividing, and then taking everything behind the 100,000,000,000 place, saving it as another integer, and treating it the end term as int1 & "." & int2 or whatever qualifies (although many code bases do not necessarily like using division operations on integers period)). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now