|
Post by jnewbie on Oct 2, 2018 20:49:24 GMT -5
Hello, I have some simple code here and I want to be able to press the button and copy the data to the clipboard. I appreciate any assistance, I have tried to read everything I can. You can reference the Copycost routine. thank you again
DTS.UPDOWN = 1 'shows updown arrows, no calendar DTS.RIGHTALIGN = 32 'aligns calendar with right side of control DTS.SHORTDATEFORMAT = 0 'default short date format: 9/22/02 DTS.LONGDATEFORMAT = 4 'long date format: Sunday, September 22, 2002 DTS.SHORTDATECENTURYFORMAT = 12 ' 9/22/2002 DTS.APPCANPARSE = 16 'double-clicking highlights entire date 'default-click highlights only one part of date
DTM.GETSYSTEMTIME = 4097'message flag to retrieve date/time chosen DTM.FIRST = 4096 'first date/time message reserved number DTM.SETMCCOLOR=4102 'message flag to set calendar background color DTM.SETMCCOLOR=DTM.FIRST+6 'numbers are often expressed this way DTM.SETSYSTEMTIME = 4098'message flag to set date/time displayed on control
MCSC.BACKGROUND = 0 'Set the background color displayed between months. MCSC.TEXT = 1 'Set the color used to display Text within a month. MCSC.TITLEBK = 2 'Set the background color displayed in the calendar's title. MCSC.TITLETEXT = 3 'Set the color used to display Text within the calendar's title. MCSC.MONTHBK=4 'Set the background color displayed within the month. MCSC.TRAILINGTEXT = 5 'Set the color used to display header day and trailing day text. 'Header and trailing days are the days from the previous and 'following months that appear on the current month calendar.
global ischecked 'global ehour 'global emin
NoMainWin struct icex, _ dwSize As ulong, _ dwICC As ulong
icex.dwSize.struct = Len(icex.struct) icex.dwICC.struct = Hexdec("100") 'ICC_DATE_CLASSES
CallDLL #comctl32, "InitCommonControlsEx", _ icex As struct, r As long
UpperLeftX = 750 UpperLeftY = 300 WindowWidth=245:WindowHeight=420
statictext #1.Title, "Calculate either the Cost, GP% or Revenue", 10,15,220,24
'window parms: Start Col, Start Row, Width, High
statictext #1.cost, "Cost: $", 10, 50, 36, 20 textbox #1.startcost, 47,50,100,20
statictext #1.gp, "GP:", 10, 74, 20, 20 textbox #1.startgp, 30,72,50,20 statictext #1.gppercent, "%", 80,74,80,20
statictext #1.ref, "Rev: $", 10, 98, 32, 20 textbox #1.startrev, 45,96,100,20
Button #1.cpycost, "Sel",[Copycost],UL,160,45,30,23 Button #1.cpygp, "Sel",[Copygp],UL,160,70,30,23 Button #1.cpyrev, "Sel",[Copyrev],UL,160,94,30,23
Button #1.clrcost, "Clr",[Clearcost],UL,195,45,30,23 Button #1.clrgp, "Clr",[Cleargp],UL,195,70,30,23 Button #1.clrgp, "Clr",[Clearrev],UL,195,94,30,23
Button #1.calc, "Calculate",[calcamount],UL,15,170,66,23 Button #1.clear, "Clear All", [ClearScrn],ul,88,170,50,23 Button #1.close, "Done",[Quit],UL,145,170,66,23
texteditor #1.resultsmsgs, 10,200,205,130 statictext #1.usecurtime, "You must supply 2 values", 55, 129, 160, 20 statictext #1.usecurtime, "It will calculate the third", 60, 145, 160, 20
Open "Calc Cost/GP/Rev" For window As #1 #1 "TrapClose [Quit]"
h1 = hWnd(#1) h2 = hWnd(#1) hInst1=InstanceHandle(h1) hInst2=InstanceHandle(h2) Wait
[Copycost] ' print #1.startcost, "!selectall";
' print #1.startcost, "!contents? scost"; print #1.startcost, "!selectall"; print #1.startcost, "!copy"
Wait
[Copygp] print #1.startgp, "!selectall"; Wait
[Copyrev] print #1.startrev, "!selectall"; Wait
[Clearcost] Print #1.startcost, "" Wait
[Cleargp] Print #1.startgp, "" Wait
[Clearrev] Print #1.startrev, "" Wait
[ClearScrn] print #1.resultsmsgs, "!cls" Print #1.startcost, "" Print #1.startgp, "" Print #1.startrev, "" Wait
[Quit] Close #1:End
[calcamount]
print #1.startgp, "!contents? sgp" print #1.startcost, "!contents? scost" print #1.startrev, "!contents? srev"
' ' how to calculate the Revenue ' if sgp > 0 and scost > 0 then actualgp = abs(sgp) actualgp = actualgp / 100 revenue = scost / ( 1 - actualgp)
print #1.resultsmsgs, "" Print #1.resultsmsgs, "Cost: $"; scost Print #1.resultsmsgs, "GP: "; actualgp * 100; "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", revenue) Print #1.startrev, using("##########.##", revenue) end if ' ' how to calculate the GP ' if scost > 0 and srev > 0 then 'actualgp = abs(sgp) 'actualgp = actualgp / 100 'revenue = scost / ( 1 - actualgp) actualgp = ((srev - scost) / srev) * 100 print #1.resultsmsgs, "" Print #1.resultsmsgs, "Cost: $"; scost Print #1.resultsmsgs, "GP: "; using("####.##", actualgp); "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", srev) Print #1.startgp, using("####.##", actualgp) end if ' ' how to calculate the Cost ' if srev > 0 and sgp > 0 then actualgp = sgp / 100 scost = srev - (actualgp * srev) print #1.resultsmsgs, "" Print #1.resultsmsgs, "Cost: $"; using("#########.##", scost) Print #1.resultsmsgs, "GP: "; using("####.##", sgp); "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", srev) Print #1.startcost, using("#########.##", scost) end if Wait
Function InstanceHandle(hW) CallDLL #user32, "GetWindowLongA", _ hW As long, _GWL_HINSTANCE As long, _ InstanceHandle As long End Function
Function GetWindowText$(hW) a=GetWindowTextLength(hW) Title$=Space$(a)+Chr$(0) l=Len(Title$) CallDLL #user32, "GetWindowTextA", hW As long,_ Title$ As ptr, l As long, result As long GetWindowText$=Trim$(Title$) End Function
Function GetWindowTextLength(hW) CallDLL #user32, "GetWindowTextLengthA",_ hW As long, GetWindowTextLength As long End Function
Sub SetBGColor hW, col DTM.SETMCCOLOR=4102 'message flag to set calendar color MCSC.MONTHBK=4 'color to change=month background
CallDLL #user32, "SendMessageA",_ hW As long, _ 'handle of control DTM.SETMCCOLOR As long,_ 'set color message MCSC.MONTHBK As long,_ 'part of control to set color on col As long,_ 'color desired re As long End Sub
|
|
|
Post by metro on Oct 2, 2018 23:03:38 GMT -5
Hi jnewbie which data are you wanting to copy @ the moment you are trying to use the copy command on a textbox used for inputting the Cost if you want to copy the result of your calculation try
print #1.resultsmsgs, "!selectall"; print #1.resultsmsgs,"!copy";
for simplicity I place the above code at the end of the branch label [calcamount] just before the wait then opened notepad and did a Ctrl "V" and got what I expected
HTH
metro
|
|
|
Post by jnewbie on Oct 3, 2018 1:24:18 GMT -5
Interesting, I didn't consider that. Thank you very much it worked.
What I was trying to do was use the Sel button next to each field to copy the contents of that field. I was testing with the CopyCost. Instead of getting all the results, I just wanted the one field. Once I get it working then I would change the 3 Sel button to do a copy instead of just selecting the data.
|
|
|
Post by metro on Oct 3, 2018 1:48:27 GMT -5
There may be a better way, Me....I would write the contents of each individual textbox to an invisible texteditor (locate off screen)
print #1.startcost, "!contents? scost" #1.HiddenTextEditor scost
then you can #1.HiddenTextEditor,"!copy"
edit: also look at changing the initial focus then the TAB order to make it easier to enter info initial focus set to Cost enter amount then press TAB enter GP then press TAB press enter to calc
UpperLeftX = 750 UpperLeftY = 300 WindowWidth=245:WindowHeight=420
statictext #1.Title, "Calculate either the Cost, GP% or Revenue", 10,15,220,24
'window parms: Start Col, Start Row, Width, High
statictext #1.cost, "Cost: $", 10, 50, 36, 20 textbox #1.startcost, 47,50,100,20
statictext #1.gp, "GP:", 10, 74, 20, 20 textbox #1.startgp, 30,72,50,20 statictext #1.gppercent, "%", 80,74,80,20 Button #1.calc, "Calculate",[calcamount],UL,15,170,66,23 statictext #1.ref, "Rev: $", 10, 98, 32, 20 textbox #1.startrev, 45,96,100,20
Button #1.cpycost, "Sel",[Copycost],UL,160,45,30,23 Button #1.cpygp, "Sel",[Copygp],UL,160,70,30,23 Button #1.cpyrev, "Sel",[Copyrev],UL,160,94,30,23
Button #1.clrcost, "Clr",[Clearcost],UL,195,45,30,23 Button #1.clrgp, "Clr",[Cleargp],UL,195,70,30,23 Button #1.clrgp, "Clr",[Clearrev],UL,195,94,30,23
'Button #1.calc, "Calculate",[calcamount],UL,15,170,66,23 Button #1.clear, "Clear All", [ClearScrn],ul,88,170,50,23 Button #1.close, "Done",[Quit],UL,145,170,66,23
texteditor #1.resultsmsgs, 10,200,205,130 statictext #1.usecurtime, "You must supply 2 values", 55, 129, 160, 20 statictext #1.usecurtime, "It will calculate the third", 60, 145, 160, 20
Open "Calc Cost/GP/Rev" For window As #1 #1 "TrapClose [Quit]"
h1 = hWnd(#1) h2 = hWnd(#1) hInst1=InstanceHandle(h1) hInst2=InstanceHandle(h2) #1.startcost,"!setfocus" Wait
|
|
|
Post by jnewbie on Oct 5, 2018 1:43:16 GMT -5
I have taken all your suggestions.. thank you very much!!! I have also added a routine to parse the data so someone could enter "$" or "," in their entry and I just go around it.
I have one final hurtle that I have not been able to figure out, not sure if I should open a new post.. I am trying to out put my number with "," as 000 separators. Tried using the "using" command but that didn't work.. like: trim$(using("###"",""####"",""###.##", revenue)) and many variations.
Here is my code so far..
DTS.UPDOWN = 1 'shows updown arrows, no calendar DTS.RIGHTALIGN = 32 'aligns calendar with right side of control DTS.SHORTDATEFORMAT = 0 'default short date format: 9/22/02 DTS.LONGDATEFORMAT = 4 'long date format: Sunday, September 22, 2002 DTS.SHORTDATECENTURYFORMAT = 12 ' 9/22/2002 DTS.APPCANPARSE = 16 'double-clicking highlights entire date 'default-click highlights only one part of date
DTM.GETSYSTEMTIME = 4097'message flag to retrieve date/time chosen DTM.FIRST = 4096 'first date/time message reserved number DTM.SETMCCOLOR=4102 'message flag to set calendar background color DTM.SETMCCOLOR=DTM.FIRST+6 'numbers are often expressed this way DTM.SETSYSTEMTIME = 4098'message flag to set date/time displayed on control
MCSC.BACKGROUND = 0 'Set the background color displayed between months. MCSC.TEXT = 1 'Set the color used to display Text within a month. MCSC.TITLEBK = 2 'Set the background color displayed in the calendar's title. MCSC.TITLETEXT = 3 'Set the color used to display Text within the calendar's title. MCSC.MONTHBK=4 'Set the background color displayed within the month. MCSC.TRAILINGTEXT = 5 'Set the color used to display header day and trailing day text. 'Header and trailing days are the days from the previous and 'following months that appear on the current month calendar.
global ischecked
NoMainWin struct icex, _ dwSize As ulong, _ dwICC As ulong
icex.dwSize.struct = Len(icex.struct) icex.dwICC.struct = Hexdec("100") 'ICC_DATE_CLASSES
CallDLL #comctl32, "InitCommonControlsEx", _ icex As struct, r As long
UpperLeftX = 750 UpperLeftY = 300 WindowWidth=245:WindowHeight=420
statictext #1.Title, "Calculate either the Cost, GP% or Revenue", 10,15,220,24
'window parms: Start Col, Start Row, Width, High
statictext #1.cost, "Cost: $", 10, 50, 36, 20 textbox #1.startcost, 47,50,100,20
statictext #1.gp, "GP:", 10, 74, 20, 20 textbox #1.startgp, 30,72,50,20 statictext #1.gppercent, "%", 80,74,80,20
statictext #1.ref, "Rev: $", 10, 98, 32, 20 textbox #1.startrev, 45,96,100,20
Button #1.cpycost, "Cpy",[Copycost],UL,160,45,30,23 Button #1.cpygp, "Cpy",[Copygp],UL,160,70,30,23 Button #1.cpyrev, "Cpy",[Copyrev],UL,160,94,30,23
Button #1.clrcost, "Clr",[Clearcost],UL,195,45,30,23 Button #1.clrgp, "Clr",[Cleargp],UL,195,70,30,23 Button #1.clrgp, "Clr",[Clearrev],UL,195,94,30,23
Button #1.calc, "Calculate",[calcamount],UL,15,170,66,23 Button #1.clear, "Clear All", [ClearScrn],ul,88,170,50,23 Button #1.close, "Done",[Quit],UL,145,170,66,23
texteditor #1.resultsmsgs, 10,200,205,130 statictext #1.usecurtime, "You must supply 2 values", 55, 129, 160, 20 statictext #1.usecurtime, "It will calculate the third", 60, 145, 160, 20
'This is just a small text window to put the vaules for the copy function texteditor #1.copymsg, 5000,200,205,20
Open "Calc Cost/GP/Rev" For window As #1 #1 "TrapClose [Quit]"
h1 = hWnd(#1) h2 = hWnd(#1) hInst1=InstanceHandle(h1) hInst2=InstanceHandle(h2) print #1.startcost, "!setfocus"; Wait
[Copycost] print #1.startcost, "!contents? copytext$"; Print #1.copymsg, copytext$; print #1.copymsg, "!selectall"; print #1.copymsg, "!copy"; print #1.copymsg, "!cls" Wait
[Copygp] print #1.startgp, "!contents? copytext$"; Print #1.copymsg, copytext$; print #1.copymsg, "!selectall"; print #1.copymsg, "!copy"; print #1.copymsg, "!cls" Wait
[Copyrev] print #1.startrev, "!contents? copytext$"; Print #1.copymsg, copytext$; print #1.copymsg, "!selectall"; print #1.copymsg, "!copy"; print #1.copymsg, "!cls" Wait
[Clearcost] Print #1.startcost, "" print #1.startcost, "!setfocus"; Wait
[Cleargp] Print #1.startgp, "" print #1.startgp, "!setfocus"; Wait
[Clearrev] Print #1.startrev, "" print #1.startrev, "!setfocus"; Wait
[ClearScrn] print #1.resultsmsgs, "!cls" Print #1.startcost, "" Print #1.startgp, "" Print #1.startrev, "" print #1.startcost, "!setfocus";
Wait
[Quit] Close #1:End
[calcamount] scost = 0 sgp = 0 srev = 0
print #1.startcost, "!contents? scost$" print #1.startgp, "!contents? sgp$" print #1.startrev, "!contents? srev"
' clean up the cost number print #1.startcost, "!contents? copytext$"; if copytext$ > "" then i = 0 newnum$ = "" for i = 1 to len(copytext$) select case mid$(copytext$, i, 1) case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." newnum$ = newnum$ + mid$(copytext$, i, 1) end select next i scost = eval(newnum$) end if
' clean up the GP number print #1.startgp, "!contents? copytext$"; if copytext$ > "" then i = 0 newnum$ = "" for i = 1 to len(copytext$) select case mid$(copytext$, i, 1) case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." newnum$ = newnum$ + mid$(copytext$, i, 1) end select next i sgp = eval(newnum$) end if
' clean up the revenue number print #1.startrev, "!contents? copytext$"; if copytext$ > "" then i = 0 newnum$ = "" for i = 1 to len(copytext$) select case mid$(copytext$, i, 1) case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." newnum$ = newnum$ + mid$(copytext$, i, 1) end select next i srev = eval(newnum$) end if
' ' how to calculate the Revenue ' if sgp > 0 and scost > 0 then actualgp = abs(sgp) actualgp = actualgp / 100 revenue = scost / ( 1 - actualgp)
Print #1.resultsmsgs, "Cost: $"; scost Print #1.resultsmsgs, "GP: "; actualgp * 100; "%" Print #1.resultsmsgs, "Revenue: $"; trim$(using("##########.##", revenue)) Print #1.startrev, trim$(using("##########.##", revenue)) print #1.resultsmsgs, "" end if ' ' how to calculate the GP ' if scost > 0 and srev > 0 then actualgp = ((srev - scost) / srev) * 100
Print #1.resultsmsgs, "Cost: $"; scost Print #1.resultsmsgs, "GP: "; trim$(using("####.##", actualgp)); "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", srev) Print #1.startgp, trim$(using("####.##", actualgp)) print #1.resultsmsgs, "" end if ' ' how to calculate the Cost ' if srev > 0 and sgp > 0 then actualgp = sgp / 100 scost = srev - (actualgp * srev)
Print #1.resultsmsgs, "Cost: $"; trim$(using("#########.##", scost)) Print #1.resultsmsgs, "GP: "; using("####.##", sgp); "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", srev) Print #1.startcost, trim$(using("#########.##", scost)) print #1.resultsmsgs, "" end if
'This will take the contents of the resutls area and automatically copy it to the clipboard. 'Don't really want to do this now that I can do each field by itself 'print #1.resultsmsgs, "!selectall"; 'print #1.resultsmsgs,"!copy";
Wait
Function InstanceHandle(hW) CallDLL #user32, "GetWindowLongA", _ hW As long, _GWL_HINSTANCE As long, _ InstanceHandle As long End Function
Function GetWindowText$(hW) a=GetWindowTextLength(hW) Title$=Space$(a)+Chr$(0) l=Len(Title$) CallDLL #user32, "GetWindowTextA", hW As long,_ Title$ As ptr, l As long, result As long GetWindowText$=Trim$(Title$) End Function
Function GetWindowTextLength(hW) CallDLL #user32, "GetWindowTextLengthA",_ hW As long, GetWindowTextLength As long End Function
Sub SetBGColor hW, col DTM.SETMCCOLOR=4102 'message flag to set calendar color MCSC.MONTHBK=4 'color to change=month background
CallDLL #user32, "SendMessageA",_ hW As long, _ 'handle of control DTM.SETMCCOLOR As long,_ 'set color message MCSC.MONTHBK As long,_ 'part of control to set color on col As long,_ 'color desired re As long End Sub
|
|
|
Post by metro on Oct 5, 2018 2:26:55 GMT -5
To make it easy to copy the code you have posted try clicking on the button the has the large "C" on it (hint next to "Quote menu button" then paste your code where it states "insert your code"
you will see with the code below I've relocated the Calc Button and used the new function on revenue
DTS.UPDOWN = 1 'shows updown arrows, no calendar DTS.RIGHTALIGN = 32 'aligns calendar with right side of control DTS.SHORTDATEFORMAT = 0 'default short date format: 9/22/02 DTS.LONGDATEFORMAT = 4 'long date format: Sunday, September 22, 2002 DTS.SHORTDATECENTURYFORMAT = 12 ' 9/22/2002 DTS.APPCANPARSE = 16 'double-clicking highlights entire date 'default-click highlights only one part of date
DTM.GETSYSTEMTIME = 4097'message flag to retrieve date/time chosen DTM.FIRST = 4096 'first date/time message reserved number DTM.SETMCCOLOR=4102 'message flag to set calendar background color DTM.SETMCCOLOR=DTM.FIRST+6 'numbers are often expressed this way DTM.SETSYSTEMTIME = 4098'message flag to set date/time displayed on control
MCSC.BACKGROUND = 0 'Set the background color displayed between months. MCSC.TEXT = 1 'Set the color used to display Text within a month. MCSC.TITLEBK = 2 'Set the background color displayed in the calendar's title. MCSC.TITLETEXT = 3 'Set the color used to display Text within the calendar's title. MCSC.MONTHBK=4 'Set the background color displayed within the month. MCSC.TRAILINGTEXT = 5 'Set the color used to display header day and trailing day text. 'Header and trailing days are the days from the previous and 'following months that appear on the current month calendar.
global ischecked
NoMainWin struct icex, _ dwSize As ulong, _ dwICC As ulong
icex.dwSize.struct = Len(icex.struct) icex.dwICC.struct = Hexdec("100") 'ICC_DATE_CLASSES
CallDLL #comctl32, "InitCommonControlsEx", _ icex As struct, r As long
UpperLeftX = 750 UpperLeftY = 300 WindowWidth=245:WindowHeight=420
statictext #1.Title, "Calculate either the Cost, GP% or Revenue", 10,15,220,24
'window parms: Start Col, Start Row, Width, High
statictext #1.cost, "Cost: $", 10, 50, 36, 20 textbox #1.startcost, 47,50,100,20
statictext #1.gp, "GP:", 10, 74, 20, 20 textbox #1.startgp, 30,72,50,20 statictext #1.gppercent, "%", 80,74,80,20
'HERE Button #1.calc, "Calculate",[calcamount],UL,15,170,66,23
statictext #1.ref, "Rev: $", 10, 98, 32, 20 textbox #1.startrev, 45,96,100,20
Button #1.cpycost, "Cpy",[Copycost],UL,160,45,30,23 Button #1.cpygp, "Cpy",[Copygp],UL,160,70,30,23 Button #1.cpyrev, "Cpy",[Copyrev],UL,160,94,30,23
Button #1.clrcost, "Clr",[Clearcost],UL,195,45,30,23 Button #1.clrgp, "Clr",[Cleargp],UL,195,70,30,23 Button #1.clrgp, "Clr",[Clearrev],UL,195,94,30,23
'MOVED Button #1.calc, "Calculate",[calcamount],UL,15,170,66,23 Button #1.clear, "Clear All", [ClearScrn],ul,88,170,50,23 Button #1.close, "Done",[Quit],UL,145,170,66,23
texteditor #1.resultsmsgs, 10,200,205,130 statictext #1.usecurtime, "You must supply 2 values", 55, 129, 160, 20 statictext #1.usecurtime, "It will calculate the third", 60, 145, 160, 20
'This is just a small text window to put the vaules for the copy function texteditor #1.copymsg, 5000,200,205,20
Open "Calc Cost/GP/Rev" For window As #1 #1 "TrapClose [Quit]"
h1 = hWnd(#1) h2 = hWnd(#1) hInst1=InstanceHandle(h1) hInst2=InstanceHandle(h2) print #1.startcost, "!setfocus"; Wait
[Copycost] print #1.startcost, "!contents? copytext$"; Print #1.copymsg, copytext$; print #1.copymsg, "!selectall"; print #1.copymsg, "!copy"; print #1.copymsg, "!cls" Wait
[Copygp] print #1.startgp, "!contents? copytext$"; Print #1.copymsg, copytext$; print #1.copymsg, "!selectall"; print #1.copymsg, "!copy"; print #1.copymsg, "!cls" Wait
[Copyrev] print #1.startrev, "!contents? copytext$"; Print #1.copymsg, copytext$; print #1.copymsg, "!selectall"; print #1.copymsg, "!copy"; print #1.copymsg, "!cls" Wait
[Clearcost] Print #1.startcost, "" print #1.startcost, "!setfocus"; Wait
[Cleargp] Print #1.startgp, "" print #1.startgp, "!setfocus"; Wait
[Clearrev] Print #1.startrev, "" print #1.startrev, "!setfocus"; Wait
[ClearScrn] print #1.resultsmsgs, "!cls" Print #1.startcost, "" Print #1.startgp, "" Print #1.startrev, "" print #1.startcost, "!setfocus";
Wait
[Quit] Close #1:End
[calcamount] scost = 0 sgp = 0 srev = 0
print #1.startcost, "!contents? scost$" print #1.startgp, "!contents? sgp$" print #1.startrev, "!contents? srev"
' clean up the cost number print #1.startcost, "!contents? copytext$"; if copytext$ > "" then i = 0 newnum$ = "" for i = 1 to len(copytext$) select case mid$(copytext$, i, 1) case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." newnum$ = newnum$ + mid$(copytext$, i, 1) end select next i scost = eval(newnum$) end if
' clean up the GP number print #1.startgp, "!contents? copytext$"; if copytext$ > "" then i = 0 newnum$ = "" for i = 1 to len(copytext$) select case mid$(copytext$, i, 1) case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." newnum$ = newnum$ + mid$(copytext$, i, 1) end select next i sgp = eval(newnum$) end if
' clean up the revenue number print #1.startrev, "!contents? copytext$"; if copytext$ > "" then i = 0 newnum$ = "" for i = 1 to len(copytext$) select case mid$(copytext$, i, 1) case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." newnum$ = newnum$ + mid$(copytext$, i, 1) end select next i srev = eval(newnum$) end if
' ' how to calculate the Revenue ' if sgp > 0 and scost > 0 then actualgp = abs(sgp) actualgp = actualgp / 100 revenue = scost / ( 1 - actualgp) '************************************************ mask$ = "###,###,###.##" '************************************************
Print #1.resultsmsgs, "Cost: $"; scost Print #1.resultsmsgs, "GP: "; actualgp * 100; "%" '************************************************************** #1.resultsmsgs, "Revenue: $" ; trim$(using$(mask$, revenue)) 'Print #1.resultsmsgs, "Revenue: $"; trim$(using("##########.##", revenue)) '*************************************************************** Print #1.startrev,trim$(using$(mask$, revenue)) print #1.resultsmsgs, "" end if ' ' how to calculate the GP ' if scost > 0 and srev > 0 then actualgp = ((srev - scost) / srev) * 100
Print #1.resultsmsgs, "Cost: $"; scost Print #1.resultsmsgs, "GP: "; trim$(using("####.##", actualgp)); "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", srev) Print #1.startgp, trim$(using("####.##", actualgp)) print #1.resultsmsgs, "" end if ' ' how to calculate the Cost ' if srev > 0 and sgp > 0 then actualgp = sgp / 100 scost = srev - (actualgp * srev)
Print #1.resultsmsgs, "Cost: $"; trim$(using("#########.##", scost)) Print #1.resultsmsgs, "GP: "; using("####.##", sgp); "%" Print #1.resultsmsgs, "Revenue: $"; using("##########.##", srev) Print #1.startcost, trim$(using("#########.##", scost)) print #1.resultsmsgs, "" end if
'This will take the contents of the resutls area and automatically copy it to the clipboard. 'Don't really want to do this now that I can do each field by itself 'print #1.resultsmsgs, "!selectall"; 'print #1.resultsmsgs,"!copy";
Wait
Function InstanceHandle(hW) CallDLL #user32, "GetWindowLongA", _ hW As long, _GWL_HINSTANCE As long, _ InstanceHandle As long End Function
Function GetWindowText$(hW) a=GetWindowTextLength(hW) Title$=Space$(a)+Chr$(0) l=Len(Title$) CallDLL #user32, "GetWindowTextA", hW As long,_ Title$ As ptr, l As long, result As long GetWindowText$=Trim$(Title$) End Function
Function GetWindowTextLength(hW) CallDLL #user32, "GetWindowTextLengthA",_ hW As long, GetWindowTextLength As long End Function
Sub SetBGColor hW, col DTM.SETMCCOLOR=4102 'message flag to set calendar color MCSC.MONTHBK=4 'color to change=month background
CallDLL #user32, "SendMessageA",_ hW As long, _ 'handle of control DTM.SETMCCOLOR As long,_ 'set color message MCSC.MONTHBK As long,_ 'part of control to set color on col As long,_ 'color desired re As long End Sub
function using$(mask$, x) delim1000$ = "," 'the point is, we do not print them (print " ") if there are no digit in this place
realMask$ = "" for i = 1 to len(mask$) c$=mid$(mask$,i,1) if instr("#.", c$) then realMask$ = realMask$ + c$ next
x$=using(realMask$, x) 'print x$
xx$="" j = 1 digitStarted=0 for i = 1 to len(mask$) c$=mid$(mask$,i,1) if instr("#.", c$) then cc$=mid$(x$,j,1) xx$ = xx$ + cc$ j=j+1 digitStarted = (instr(" -", cc$)=0) else if instr(delim1000$, c$) then if digitStarted = 0 then if cc$="-" then 'if we have " -," we should convert it to " -" xx$ = left$(xx$, len(xx$)-1) + " " c$="-" else c$=" " 'skip thousand delimiter if digits not started yet end if end if end if xx$ = xx$ + c$ end if next using$ = xx$ end function
The function is not mine so the credit goes to its author
randomize .5 print "String";tab(15);"Val";tab(30);"Using";tab(50);"using$" for i = 1 to 20 n = int(rnd(1)*10) a$="" for j = 1 to n a$=a$;int(rnd(1)*10) next a$=a$;"." for j = 1 to 3 a$=a$;int(rnd(1)*10) next if rnd(1)<0.5 then a$="-";a$ a=val(a$) print a$;tab(15);a;tab(30);using("############.##", a);tab(50);using$("###,###,###,###.##", a) next print print "Also can do:" x=1234567.8901 mask$ = "###,###,###.##" print x, ">";mask$;"<", ">";using$(mask$, x);"<" mask$ = "x=###,###,###.##$" print x, ">";mask$;"<", ">";using$(mask$, x);"<" mask$ = "any text ###,###,###.## more" print x, ">";mask$;"<", ">";using$(mask$, x);"<" mask$ = "### ###,###.##" print x, ">";mask$;"<", ">";using$(mask$, x);"<" mask$ = "### ### ###.##" print x, ">";mask$;"<", ">";using$(mask$, x);"<" function using$(mask$, x) delim1000$ = "," 'the point is, we do not print them (print " ") if there are no digit in this place realMask$ = "" for i = 1 to len(mask$) c$=mid$(mask$,i,1) if instr("#.", c$) then realMask$ = realMask$ + c$ next x$=using(realMask$, x) 'print x$ xx$="" j = 1 digitStarted=0 for i = 1 to len(mask$) c$=mid$(mask$,i,1) if instr("#.", c$) then cc$=mid$(x$,j,1) xx$ = xx$ + cc$ j=j+1 digitStarted = (instr(" -", cc$)=0) else if instr(delim1000$, c$) then if digitStarted = 0 then if cc$="-" then 'if we have " -," we should convert it to " -" xx$ = left$(xx$, len(xx$)-1) + " " c$="-" else c$=" " 'skip thousand delimiter if digits not started yet end if end if end if xx$ = xx$ + c$ end if next using$ = xx$ end function
|
|