Reinstalled my dev machine with win 8.1
Enabled ASP, installed my legacy websites that I have to maintain, installed sites as an application in IIS, enabled parent paths, send errors to browser on, full detail set on in error pages. All is working well, except when I work with numbers
I'm working in a system that captures financial data inputted by users, so often a number will be: 100.0 or
100.000 or
100 or
100,00
so I have a function that (I've used on loads of websites in the past) that will standardise the irregularities into a constant format, such as 100.00 (ie: proper decimal, always using a dot, etc)
This line now fails on win 8.1 IIS 8.5: If Cdbl(myString) = Cdbl(0) Then
Function ProperDecimal(s_String)
Dim CharPlace, DotChar, iLoop, strCurrentChar, myString
myString = TRIM(s_String)
If ISNULL(myString) OR myString = "" Then myString = 0
myString = REPLACE(myString,",",".")
'Find where the comma or dot is, ie: 100.00 is in position 3 (from the right)
CharPlace = 1
DotChar = 0
For iLoop = Len(Replace(myString, " ", "")) to 1 Step -1
strCurrentChar = mid(Replace(myString, " ", ""), iLoop, 1)
If strCurrentChar = "." OR strCurrentChar = "," Then
DotChar = CharPlace
Exit For
End If
CharPlace = CharPlace + 1
Next
'If string is zero, leave it at zero, we dont need 0.00
If Cdbl(myString) = Cdbl(0) Then
'ignore it, no decimal places needed
ProperDecimal = myString
Else
'Where is the DOT
Select Case DotChar
Case 0 'eg: 100 will be converted to 100.00
ProperDecimal = (myString & ".00")
Case 1 'eg: 100. will be converted to 100.00
ProperDecimal = (myString & "00")
Case 2 'eg: 100.0 will be converted to 100.00
ProperDecimal = (myString & "0")
Case 3 'eg: 100.00 will remain
ProperDecimal = (myString)
Case Else '(4, 5, 6, 7, 8, etc) 'eg: 100.001
ProperDecimal = ProperDecimal(Round(myString,2))
End Select
End If
End Function
Call ProperDecimal("112.05")
This lead me to try other methods other than CDbl
Response.write(isNumeric(s_String)) 'works, returns false because this is a string
Response.write(CINT(myString))
Response.write(CLNG(myString))
Response.write(CDBL(myString))
Returns this:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CINT'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CLNG'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CDBL'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CINT'
If I then change the If statement to convert the 0 to a string, it works:
If myString = CSTR(0) Then
But I really dont want to be comparing strings to strings especially with numbers
This is now the second project this is happening on. The previous project I had to change the decimal comma to a fullstop (112,05 had to be 112.05) so I thought it had something to do with regional settings and the comma being listed as decimal character. But am getting different results now, its driving me up the wall.. plz assist if you can. Ta
CInt on the server works fine (2008 R2), on the clients pc (windows Xp and windows 7) but on my windows 8 machine, this is an issue.
I made my own two functions which I use now instead of CInt and CDbl. You can make more if needed. Pretty simple and tested,
EDIT:
Changed the function names toe shorter versions. Easier to replace and to use. Also does not clash with Javascripts parseInt if you do a search
Function pInt(Str)
Dim val : val = 0
'==Test Comma=='
On Error Resume Next
val = CInt(Replace(Str, ".", ","))
'==Test Period=='
On Error Resume Next
val = CInt(Replace(Str, ",", "."))
On Error Goto 0
pInt = val
End Function
Function pDbl(Str)
Dim val : val = 0
'==Test Comma=='
On Error Resume Next
val = CDbl(Replace(Str, ".", ","))
'==Test Period=='
On Error Resume Next
val = CDbl(Replace(Str, ",", "."))
On Error Goto 0
pDbl = val
End Function
I am not a pro in ClassicASP/VBScript but this works. I like my C# ASP.net
Related
In MS Project Professional I have a custom field that returns the correct value...sometimes, no value at other times, and an #ERROR at still other times with no apparent rhyme or reason.
The goal: I need to capture the [Resource Names] field for use in an external application - easy enough - but when I have a fixed units task with limited resource units I need to exclude the "[##%]" portion of the name. Example: Sam[25%] but I need just, "Sam"
The formula: IIf(IsNumeric(InStr(1,[Resource Names],"[")),LEFT([Resource Names],Len([Resource Names])-5),[Resource Names])
The results are in summary:
Marian == M
Sam == #ERROR
Sam[25%] == Sam
IDNR == #ERROR
Core Dev == Cor
Bindu == Bindu
Bindu[50%] == Bindu
Michele == Mi
Michele[25%] == Michele
Disha == empty
Disha[33%] == Disha
Stuart[50%] == Stuart
Stuart == S
Strangely enough, Summary Tasks show no value which is correct.
The need: can someone help me fix the formula? Or, should I just suck it up and manually delete the offending brackets and numbers?
If you only ever have one resource assigned to a task, this formula will work: IIf(0=InStr(1,[Resource Names],"["),[Resource Names],Left([Resource Names],InStr(1,[Resource Names],"[")-1)).
However, building a formula to handle more than one resource would be extremely tedious with the limited functions available. In that case a macro to update the field would work much better:
Sub GetResourceNames()
Dim t As Task
For Each t In ActiveProject.Tasks
Dim resList As String
resList = vbNullString
Dim a As Assignment
For Each a In t.Assignments
resList = resList & "," & a.Resource.Name
Next a
t.Text2 = Mid$(resList, 2)
Next t
End Sub
I am writing this code and have recently come across an error. I have no idea why this is happening. In theory, the english alphabet should be being printed. However, instead of the english alphabet, symbols are being printed instead.
I can not paste the symbols for some reason, but if you ran the code yourself, you'll understand what I mean.
My full code is posted below.
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVWXYZ0123456789"
choice = input("Would you like to encrypt or decrypt? [e/d]: ")
if choice == "e":
message = input("Please insert the message you would like to use: ")
keyword = input("Please insert the keyword you would like to use: ")
ik = len(keyword)
i = 0
string = ''
for A in message:
message1 = (ord(A)) - 96
key1 = (ord(keyword[i])) - 96
addition = message1 + key1
string += (chr(addition))
if i >= ik:
i = 0
else:
i += 1
print (string)
You need to add back the 96 you originally took away :) Alternatively, use the Caesar cipher formula as adding back 96 will still result in symbols appearing (I did the ocr coursework already)
addition = message1 + key1 + 96
your code will not work if the keyword is shorter than the message, so use the modulo operator (%) on i with the length of the keyword inside the line:
key1 = (ord(keyword[i])) - 96
I've just started coding ABAP for a few days and I have a task to call the report from transaction SE38 and have
the report's result shown on the screen of the WebDynPro application SE80.
The report take the user input ( e.g: Material Number, Material Type, Plant, Sale Org. ) as a condition for querying, so the WebDynPro application must allow user to key in this parameters.
In some related article they were talking about using SUBMIT rep EXPORTING LIST TO MEMORY and CALL FUNCTION 'LIST_FROM_MEMORY' but so far I really have no idea to implement it.
Any answers will be appreciated. Thanks!
You can export it to PDF. Therefore, when a user clicks on a link, you run the conversion and display the file in the browser window.
To do so, you start by creating a JOB using the following code below:
constants c_name type tbtcjob-jobname value 'YOUR_JOB_NAME'.
data v_number type tbtcjob-jobcount.
data v_print_parameters type pri_params.
call function 'JOB_OPEN'
exporting
jobname = c_name
importing
jobcount = v_number
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc = 0.
commit work and wait.
else.
EXIT. "// todo: err handling here
endif.
Then, you need to get the printer parameters in order to submit the report:
call function 'GET_PRINT_PARAMETERS'
exporting
destination = 'LP01'
immediately = space
new_list_id = 'X'
no_dialog = 'X'
user = sy-uname
importing
out_parameters = v_print_parameters
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
v_print_parameters-linct = 55.
v_print_parameters-linsz = 1.
v_print_parameters-paart = 'LETTER'.
Now you submit your report using the filters that apply. Do not forget to add the job parameters to it, as the code below shows:
submit your_report_name
to sap-spool
spool parameters v_print_parameters
without spool dynpro
with ...(insert all your filters here)
via job c_name number v_number
and return.
if sy-subrc = 0.
commit work and wait.
else.
EXIT. "// todo: err handling here
endif.
After that, you close the job:
call function 'JOB_CLOSE'
exporting
jobcount = v_number
jobname = c_name
strtimmed = 'X'
exceptions
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
others = 8.
if sy-subrc = 0.
commit work and wait.
else.
EXIT. "// todo: err handling here
endif.
Now the job will proceed and you'll need to wait for it to complete. Do it with a loop. Once the job is completed, you can get it's spool output and convert to PDF.
data v_rqident type tsp01-rqident.
data v_job_head type tbtcjob.
data t_job_steplist type tbtcstep occurs 0 with header line.
data t_pdf like tline occurs 0 with header line.
do 200 times.
wait up to 1 seconds.
call function 'BP_JOB_READ'
exporting
job_read_jobcount = v_number
job_read_jobname = c_name
job_read_opcode = '20'
importing
job_read_jobhead = v_job_head
tables
job_read_steplist = t_job_steplist
exceptions
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 3
others = 4.
read table t_job_steplist index 1.
if not t_job_steplist-listident is initial.
v_rqident = t_job_steplist-listident.
exit.
else.
clear v_job_head.
clear t_job_steplist.
clear t_job_steplist[].
endif.
enddo.
check not v_rqident is initial.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = v_rqident
dst_device = 'LP01'
tables
pdf = t_pdf
exceptions
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others = 12.
If you're going to send it via HTTP, you may need to convert it to BASE64 as well.
field-symbols <xchar> type x.
data v_offset(10) type n.
data v_char type c.
data v_xchar(2) type x.
data v_xstringdata_aux type xstring.
data v_xstringdata type xstring.
data v_base64data type string.
data v_base64data_aux type string.
loop at t_pdf.
do 134 times.
v_offset = sy-index - 1.
v_char = t_pdf+v_offset(1).
assign v_char to <xchar> casting type x.
concatenate v_xstringdata_aux <xchar> into v_xstringdata_aux in byte mode.
enddo.
concatenate v_xstringdata v_xstringdata_aux into v_xstringdata in byte mode.
clear v_xstringdata_aux.
endloop.
call function 'SCMS_BASE64_ENCODE_STR'
exporting
input = v_xstringdata
importing
output = v_base64data.
v_base64data_aux = v_base64data.
while strlen( v_base64data_aux ) gt 255.
clear t_base64data.
t_base64data-data = v_base64data_aux.
v_base64data_aux = v_base64data_aux+255.
append t_base64data.
endwhile.
if not v_base64data_aux is initial.
t_base64data-data = v_base64data_aux.
append t_base64data.
endif.
And you're done!
Hope it helps.
As previous speakers said, you should do extensive training before implementing such stuff in productive environment.
However, calling WebdynPro ABAP within report can be done with the help of WDY_EXECUTE_IN_PLACE function module. You should pass there Webdyn Pro application and necessary parameters.
CALL FUNCTION 'WDY_EXECUTE_IN_PLACE'
EXPORTING
* PROTOCOL =
INTERNALMODE = ' '
* SMARTCLIENT =
APPLICATION = 'Z_MY_WEBDYNPRO'
* CONTAINER_NAME =
PARAMETERS = lt_parameters
SUPPRESS_OUTPUT =
TRY_TO_USE_SAPGUI_THEME = ' '
IMPORTING
OUT_URL = ex_url
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
I'm am using the following query in Sqlite3:
SELECT
Platform,
SUM((CASE WHEN Result=='Pass' THEN 1 ELSE 0 END) AS NumPass),
SUM((CASE WHEN Result =='Fail' THEN 1 ELSE 0 END) AS NumFail),
SUM((CASE WHEN Result=='NoRun' THEN 1 ELSE 0 END) AS NumNoRun),
SUM((count(Result) as NumTotal))
FROM automation_test_auto GROUP BY Platform";
and getting an error
near "AS": syntax error.
What I want to do is to find the number of pass,fail and norun cases in the database for a specific platform.
A prototype of my table is:
Platform, Result
XP, pass
XP, pass
Win8, fail
Win8, pass
Win8, pass
XP, fail
XP, fail
Win8, norun
SELECT Platform,
SUM(Result = 'Pass') AS NumPass,
SUM(Result = 'Fail') AS NumFail,
SUM(Result = 'NoRun') AS NumNoRun,
count(Result) as NumTotal
FROM automation_test_auto
GROUP BY Platform
Ok I am new with writing VBScript and I want to write a string of code that plays a file (WAV format) only on a certain day and only between specific times. After piecing together multiple fragments of code I found on the internet I was left with the following:
Dim myDateString
Dim thing1
thing1 = 0
myDateString = Date()
If myDateString < "13/08/13" Then
thing1 = 1
end if
if thing1 = 1 then
If myDateString > "15/08/13" Then
thing1 = 2
end if
end if
if thing1 = 2 then
hournow = hour(Time())
If hour(Time()) >= 9 And Hour(Now()) < 22 Then
set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
WshShell.Run "wmplayer """ & music & """",0,True
Else
wscript.quit 1
End If
Else
wscript.quit 1
End If
Ok so I had set this for the date I ran this on, within the hour I was in. But
it didn't work. I expected the VBS to start playing MYSOUND.wav but it didn't. When running the file
there were no errors though, so I was wondering what I did wrong!
I running Windows 7
If anyone could tell me what I did wrong, and how to fix it that would be great.
Double points if anyone could post a corrected version of the code!
Thanks to any answers!
First, indent your code and give your variables meaningful names!
Then, your date comparison doesn't work because you're trying to compare strings as if they were dates. This usually won't work (depending on your "system locale"): you need to use date type variables and an actual date comparison function (DateDiff in VBScript).
(EDIT: as Ansgar Wiechers pointed out, you don't need to use DateDiff to compare dates in VBScript, "DateStart <= Now And Now <= DateEnd" will do just fine)
Try this:
Dim DateStart, DateEnd, WshShell, music
DateStart = DateSerial(2013, 8, 13)
DateEnd = DateSerial(2013, 8, 15)
If DateDiff("D", DateStart, Now) >= 0 And DateDiff("D", Now, DateEnd) >= 0 Then
If Hour(Now) >= 9 And Hour(Now) < 22 Then
'*** delete after debugging ***
MsgBox "play sound"
Set WshShell = CreateObject("WScript.Shell")
music = "C:\Users\MYUSERNAME\Desktop\MYSOUND.wav"
'*** 2nd parameter : 0 hides wmplayer, 1 shows it ***
WshShell.Run "wmplayer """ & music & """", 1, True
Else
'*** delete after debugging ***
MsgBox "Not the right time"
End If
Else
'*** delete after debugging ***
MsgBox "Not the right day"
End If
Also, if you want to debug a small script like this, you can call MsgBox to do a simple tracking of what's actually executed (in your example, replacing your "WScript.Quit 1" by MsgBox would show you that the date is not properly compared.