Request.Querystring i Classic ASP - asp-classic

If I have these to lines of classic asp, I get an error.
KId = (Request.Querystring("KID") - 1000000) / 1531
KNr = ""&Request.Querystring("Knr")
If I comment out one of them, there is no error.
As I remember, I don't need to put anything at the end of each code to end a line, am I right?

You don't need to put anything at the end of the line.
I think you need to cast the querystring to an int before you can do math on it:
KId = (cInt(Request.Querystring("KID")) - 1000000) / 1531
KNr = ""&Request.Querystring("Knr")
I don't have a classic asp test bed to check for sure.

Related

Sabre Scribe Scripting Specifically Looping

Anybody have any tips for looping, and continue? For example, I placed about 2500 pnrs on a queue, and I need to add a remark to each of them. Is it possible for a script to add the remark then move to the next pnr?
For example, I placed about 2500 pnrs on a queue, and I need to add a remark to each of them. Is it possible for a script to add the remark then move to the next pnr?
Loops are supported in Scribe but have to be built manually by creating your own iteration variables and breaking the loop manually when you know the work is complete.
What you are describing is definitely possible, but working in queues can be difficult as there are many possible responses when you try to end the PNRs. You'll have to capture the response to detect whether you need to do something else to get out of the error condition (e.g. if a PNR warning indicates you have to double-end the record).
If possible, its likely simpler to work off the queue by collecting all PNR locators and then looping through that list, adding your remarks, and then ending the PNRs. You'll still have to capture the response to determine if the PNR is actually ended properly, but you won't have to deal with the buggy queue behavior. A basic Scribe loop sample is below. Note that I haven't been a Scribe developer for a while and I did this in Notepad so there might be some errors in here, but hopefully it's a good starting point.
DEFINE [ROW=N:8] ;iteration variable/counter
DEFINE [LOCATOR_FILE=*:60] ;File Path
DEFINE [TEMP_LOCATOR=*:6] ;pnr locator variable, read from the temp file
DEFINE [BREAK=*:1] ;loop breaking variable
OPEN F=[TEMP_LOCATOR] L=0 ;open the file of locators
[BREAK] = ""
[ROW] = 0
REPEAT
[ROW] = [ROW] + 1
[TEMP_LOCATOR] = "" ;Reset temp locator variable, this will break our loop
READ F=[LOCATOR_FILE] R=[ROW] C=1 [TEMP_LOCATOR]
IF $[TEMP_LOCATOR] = 6 THEN ;test length of locator, if this is 6 chars, you have a good one, pull it up and add your remark
»"5YOUR REMARK HERE"{ENTER}«
»ER{ENTER}«
;trap errors
READ F="EMUFIND:" R=0 C=0 [TEMP_LOCATOR] ;read for the locator being present on this screen, which should indicate that the ER was successful - you'll have to trap other errors here though
IF [#SYSTEM_ERROR] = 0 THEN ;this locator was found, ER appears successful
»I{ENTER}« ;Ignore this PNR and move to the next one
ELSE
[BREAK] = "Y" ;error found afeter ER, break loop. Maybe show a popup box or something, up to you
ENDIF
ELSE ;No locator found in file, break the loop
[BREAK] = "Y"
ENDIF
UNTIL [BREAK] = "Y"
CLOSE [LOCATOR_FILE]

Modelica: when initial print only once

I have the following Modelica code, inside a component that is used several times in a system model:
parameter fileName = "world.log"
equation
when initial() then
if not Modelica.Utilities.Files.exist(fileName) then
Streams.print("Hello World", fileName);
end if;
end when;
I would expect to find exactly one line of code in the created file, but instead there are usually 5 or more lines printed, but sometimes it seems to work as expected. Using Dymola 2019 on Windows 10.
Can someone clarify what is going on? The file existance check seems to be unreliable!?
when initial() is not related to events at all. It is transformed into an initial equation and may thus execute multiple times. External objects are much more reliable when it comes to executing equations only once.
Based on the previous answers and comments, the following seems to work:
parameter fileName = "world.log"
protected
Modelica.SIunits.Time startTime;
equation
when initial() then
startTime := time;
end when;
when time >= startTime then
if not Modelica.Utilities.Files.exist(fileName) then
Streams.print("Hello World", fileName);
end if;
end when;

How to write some amounts to a File?

I'm doing this program for a class; I have a listbox with 4 choices that are counted each time they're selected,and i'm supposed to write out the results to an out.File so that they can then be retrieved and displayed when asked to.
Here's an image,so you can see what i mean.
Here's the code i got for the file part so far:
'declare a streamwriter variable
Dim outFile As IO.StreamWriter
'open file for output
outFile = IO.File.CreateText("Commercials.txt")
'write to file
For intIndex As Integer = 0 To lstCommercial.Items.Count - 1
outFile.WriteLine(lstCommercial.Items(intIndex))
Next intIndex
'close th efile
outFile.Close()
So my problem is this,i can get everything to work except for it to write the totals to the file,with the result of not displaying. How do i go about doing this? What am i doing wrong in any case?
It depends on what lstCommercial.Items is.
If it is a Collection object, then you can get the index of an item using the following:
outFile.WriteLine(lstCommercial.Items.Item(intIndex))
If it is an array, then instead of using the Count property to find the length, you should rather use GetUpperBound(0) to find the last index:
For intIndex As Integer = 0 To lstCommercial.Items.GetUpperBound(0)
I have very little experience in Visual Basic so I am probably wrong, but I have just gathered this from reading Arrays in Visual Basic and Collection Object (Visual Basic).
Also, looking at the docs here, you may need to 'Flush' the buffer to the file before closing it:
outFile.Flush()
'close the file
outFile.Close()

converting classic vb to vb.net

what is the vb.net equivalent or similar of recordset.underlyingvalue and recordset.value in vb?
I'm converting a vb application to vb.net and i've replaced the recordsets with datasets but i have not been able to figure this out. any help would be really appreciated.
i've tried making a copy of the dataset and comparing values to track the changes but that doesn't seem very efficient. Here is a piece of code that i'm trying to convert.
For Each fld In rs.Fields
bfldChanged = False
Select Case fld.Type
Case adDate, adDBDate, adDBTime, adDBTimeStamp:
If IsDate(fld.UnderlyingValue) And Not IsDate(fld.Value) Then
bfldChanged = True
ElseIf Not IsDate(fld.UnderlyingValue) And IsDate(fld.Value) Then
bfldChanged = True
ElseIf IsDate(fld.UnderlyingValue) And IsDate(fld.Value) Then
If fld.UnderlyingValue <> fld.Value Then
bfldChanged = True
Else
bfldChanged = False
End If
Else
bfldChanged = False
End If
Case Else:
If (fld.UnderlyingValue <> fld.Value) Then
bfldChanged = True
Else
bfldChanged = False
End If
End Select
Next
There is no equivalent to that particular property. Data Access in .NET is very different than Data Access in VB6 and prior. The DataTable is only marginally like a RecordSet.
However, looking at the code, it looks like you're just checking to see if the table contains changes. You can use the DataTable.GetChanges() method to determine this a lot more simply.
Not part of the official answer, but a general recommendation.
I've converted tons of VB6 apps to .NET apps, and experience has taught me that doing a line-by-line conversion attempt is almost always a bad idea. The two are quite different, and in every case, it's proved to be more efficient and eror-free to just start over from scratch. Make sure I understand what the VB6 app did (requirementes) map it all out, flowchart everything, and then build the .NET version from scratch. I've had nothing but headaches doing it any other way.

Vendors black box function can only be called successfully once

(first question here, sorry if I am breaking a piece of etiquette)
My site is running on an eCommerce back end provider that I subscribe to. They have everything in classic ASP. They have a black box function called import_products that I use to import a given text file into my site's database.
The problem is that if I call the function more than once, something breaks. Here is my example code:
for blah = 1 to 20
thisfilename = "fullcatalog_" & blah & ".csv"
Response.Write thisfilename & "<br>"
Response.Flush
Call Import_Products(3,thisfilename,1)
Next
Response.End
The first execution of the Import_Products function works fine. The second time I get:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'i'
The filenames all exist. That part is fine. There are no bugs in my calling code. I have tried checking the value of "i" before each execution. The first time the value is blank, and before the second execution the value is "2". So I tried setting it to null during each loop iteration, but that didn't change the results at all.
I assume that the function is setting a variable or opening a connection during its execution, but not cleaning it up, and then not expecting it to already be set the second time. Is there any way to find out what this would be? Or somehow reset the condition back to nothing so that the function will be 'fresh'?
The function is in an unreadable include file so I can't see the code. Obviously a better solution would be to go with the company support, and I have a ticket it in with them, but it is like pulling teeth to get them to even acknowledge that there is a problem. Let alone solve it.
Thanks!
EDIT: Here is a further simplified example of calling the function. The first call works. The second call fails with the same error as above.
thisfilename = "fullcatalog_testfile.csv"
Call Import_Products(3,thisfilename,1)
Call Import_Products(3,thisfilename,1)
Response.End
The likely cause of the error are the two numeric parameters for the Import_Products subroutine.
Import_Products(???, FileName, ???)
The values are 3 and 1 in your example but you never explain what they do or what they are documented to do.
EDIT Since correcting the vender subroutine is impossible, but it always works for the first time it's called lets use an HTTP REDIRECT instead of a FOR LOOP so that it technically only gets called once per page execution.
www.mysite.tld/import.asp?current=1&end=20
curr = CInt(Request.QueryString("current"))
end = CInt(Request.QueryString("end"))
If curr <= end Then
thisfilename = "fullcatalog_" & curr & ".csv"
Call Import_Products(3,thisfilename,1)
Response.Redirect("www.mysite.tld/import.asp?current=" & (curr + 1) & "&end=" & end)
End If
note the above was written inside my browser and is untested so syntax errors may exist.

Resources