Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I convert this equation for use in aspect? 1

Status
Not open for further replies.

sharook

Programmer
Aug 22, 2006
21
US
I have this calculation that I use in this little C prog that I wrote and want to use it in aspect. Any suggestions?

Thank you
 
Post the calculation and maybe we can help.

 
duh...here it is.

Temp = ( (float) uiYear / 7.0 ) / (float) (uiMonth + uiDay + uiHours);
Tel = (unsigned int) (Temp * 10000.0);
 
unsigned int uiMonth;
unsigned int uiDay;
unsigned int uiYear;
unsigned int uiHours;
unsigned int Tel;
float Temp;
 
Do you want Tel to be an int or float? What is an example of Tel's value after this?
 
Tel needs to be an int. An example of the end result would be 79603.
 
Give this a try with your data and see if it comes out OK:

Code:
proc main
   integer uiMonth, uiDay, uiYear, iHours, Tel
   float Temp
   
   Temp = ( uiYear / 7.0 ) / (uiMonth + uiDay + uiHours)
   Tel = (Temp * 10000.0)
endproc

 
Hello Knob,

Thank you for your assistance so far. I started on that same path, so it looks like we were thinking about the same approach. If you don't mind, I kind of need to switch gears a bit as I can't seem to get termreads working properly. When the user logs in, the program will need to read in the time/date variables to actually do the equation. However, I am definitely doing something wrong. The program does a Ctrl+T to the system to get the variables. An example is shown below:

Logon: November 17, 2006, 16:30:58

I accomplish this activity on line 42.

Here's what I came up with so far today. I'm still a rookie with aspect, so please forgive me for any newb errors.

;***global vars***

integer check_msg

;***************************************************************
;* *
;* PROCEDURE Main *
;* *
;***************************************************************
proc main

call BackdoorLogin

endproc

;***************************************************************
;* *
;* PROCEDURE BackdoorLogin *
;* *
;***************************************************************
proc BackdoorLogin

integer uiMonth;
integer uiDay;
integer uiYear;
integer uiHour;
float TelPassword;
integer done = 0;
string sMonth;
string sDate;
string sYear;
string sHour;
string InputStr;
string TempStr;
string UserNameStr;
string PasswordStr;
string MonthNo;
string logonmsg;
float Temp;

while done == 0
transmit "^T^M"
pause 1
locate $Row-1 0
termreads logonmsg
strsearch logonmsg "Logon" check_msg ;Check to see that the friggin user needs to login.
if check_msg == 1

strtok TempStr InputStr " " 1 ; Logon: Ignore
strtok sMonth InputStr " " 1 ; Month
MonthNo = GetMonthInt(sMonth) ; Convert month to string No.
strtok sDate InputStr ", " 1 ; Date
strtok TempStr InputStr " " 1 ; ',' Ignor
strtok sYear InputStr " " 1 ; Year
strtok TempStr InputStr " " 1 ; ',' Ignor
strtok sHour InputStr " :" 1 ; Hour
strtonum sMonth uiMonth
strtonum sYear uiYear
strtonum sDate uiDay
strtonum sHour uiHour
Temp = ( uiYear / 7.0 ) / (uiMonth + uiDay + uiHour);
TelPassword = ( Temp * 10000.0 );

strfmt UserNameStr "BlahBlahBlah^M"
strfmt PassWordStr "%s^M" TelPassWord

transmit UserNameStr
waitfor "Password: " 4

transmit PassWordStr

waitfor "Main Menu" 1

if strfind TempStr ">"
statmsg "Login Successful"
done = 1
elseif strfind TempStr "R>"
statmsg "Login Successful"
done = 1
else
statmsg "Login Failed, please retry"
endif
pause 1

statmsg ""

else

termmsg "`r`nYou are already logged in. There's no point in running this script!`r`n"
done = 1

endif

endwhile

endproc

;***************************************************************
;* *
;* FUNCTION GetMonthInt *
;* *
;***************************************************************

func GetMonthInt:string
param string MonthInput
string MonthString = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,"
string TempStr
integer j

j = 0
while j < 13
j++
strtok TempStr MonthString "," 1
if strnicmp TempStr MonthInput 3
itoa j TempStr
return TempStr ; Return the No. of month in string
endif
endwhile
return 0
endfunc
 
Hi, sorry to take so long to get back to you, was out of town for an early Thanksgiving. Are you still having problems getting the data or is it in parsing the date/time string? If you are having problems getting the data from the string, I would recommend using termgets instead of locate/termreads. If you are having problems with strtok, I would recommend using strextract instead, keying off the single spaces as well.

 
No worries on the time. I just appreciate the help. So far, I have tried termgets, comread, and a couple of other things and I can't seem to read the date in. I have been using the usermsg to see what I am getting. I can get it to read the word Logon, but that's it. I think if I can read the string in properly, parsing it may be the easier part.
 
Ok, I finally got it to grab the date/time string:

while done == 0

transmit "^[" ; escape back to the beginnig
comread InputStr 50 1
termmsg InputStr

if strfind InputStr "Logon"
transmit "^T^M"
InputStr = ""

comread InputStr 30 1
termmsg InputStr

usermsg "The input string is: %s" InputStr

So the inputstr shows whatever date is printed after I hit Ctrl+T. Now, I just have to figure out the extract part.
 
Almost there, I just need to figure out how to drop the two digits after the decimal.
 
Figured it out, I will post the final here in a sec.
 
Sounds like you are making some progress. If the :NN is the last three characters of the string, you could use strlen to get the length of the string and then use strdelete as below to chop the last three characters off:

strdelete StrVal iLen-3 3

where StrVal is the name of your string and iLen holds the length of that string.

 
Here's the final. I didn't bother doing any real checking to see if they are logged in already because if they are logged in, they don't really need the script.

;***************************************************************
;* *
;* PROCEDURE Main *
;* *
;***************************************************************
proc main

call BackdoorLogin

endproc

;***************************************************************
;* *
;* PROCEDURE BackdoorLogin *
;* *
;***************************************************************
proc BackdoorLogin

float uiMonth;
float uiDay;
float uiYear;
float uiHour;
float TelPassword;
integer done = 0;
string MonthNo = "";
string sMonth;
string sDate;
string sYear;
string sHour;
string InputStr1 = "";
string InputStr2 = "";
string TempStr = "";
string UserNameStr = "";
string PasswordStr = "";
float Temp;

while done == 0

transmit "^[" ; escape back to the beginnig
comread InputStr1 50 1
termmsg InputStr1

if strfind InputStr1 "Logon"
transmit "^T^M"
InputStr2 = ""

comread InputStr2 30 1
termmsg InputStr2

strtok sMonth InputStr2 " " 1 ; Month
MonthNo = GetMonthInt(sMonth) ; Convert month to string No.
strtok sDate InputStr2 ", " 1 ; Date
strtok sYear InputStr2 ", " 1 ; Year
strtok sHour InputStr2 ", :" 1 ; Time

strtonum MonthNo uiMonth
strtonum sDate uiDay
strtonum sYear uiYear
strtonum sHour uiHour

Temp = ( uiYear / 7.0 ) / (uiMonth + uiDay + uiHour);
TelPassword = Temp * 10000.0;

strfmt UserNameStr "*************^M"
strfmt PassWordStr "%5.0f^M" TelPassWord

transmit UserNameStr
waitfor "Password: " 4

transmit PassWordStr

else

termmsg "`r`nYou are probably already logged in. `r`nThere's no point in running this script!`r`n"
done = 1

endif

done = 1

endwhile

endproc

;***************************************************************
;* *
;* FUNCTION GetMonthInt *
;* *
;***************************************************************

func GetMonthInt:string
param string MonthInput
string MonthString = "January,February,March,April,May,June,July,August,September,October,November,December,"
string TempStr
integer j

j = 0
while j < 13
j++
strtok TempStr MonthString "," 1
if strnicmp TempStr MonthInput 3
itoa j TempStr
return TempStr ; Return the No. of month in string

endif
endwhile
return 0
endfunc


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top