VBScript help

Discussion in 'Computer Science & Culture' started by original, Dec 7, 2009.

Not open for further replies.
1. originalsineRegistered Senior Member

Messages:
924
I do not have a strong computer science background, and yet I am using Crystal Reports 9, attempting to clean up some code for the sake of efficiency. Right now there are a lot of IF{} THEN{} ELSE statements in every report that take a few hours to completely update, which is necessary whenever a new employee is hired and assigned an ID number. What I would like to do is refer to a file that has these statements (or else an array), and then all I would have to do is update the file instead of each individual report. If you have any suggestions, I would appreciate your input... er... output.

3. MickmeisterRegistered Senior Member

Messages:
812
Why don't you use the select case statement?

5. CheskiChipsBannedBanned

Messages:
3,538
Well...depending on whatever the case is there's a couple things you can do.

You could build a buffered reader to read a text file that stores information something like...
|#####All of My Information until |where the '|' is the break code. Would basically just need a for loop to search the text file.

However; you've been unclear on what exactly it is you want.

Last edited: Dec 8, 2009

7. originalsineRegistered Senior Member

Messages:
924
I'll explain as best I can with my limited education regarding this subject. Honestly, I don't even know if this is VBScript, but I know Crystal Reports supports SQL.

There are several reports that compile a summary of the workload for partners at an accounting firm. When a client is assigned to a partner, the partner's ID number is entered in the "CLIENT.Partner" field. The report searches the client database and sorts it by employee ID number so that we can see what the volume of their workload amounts to, but instead of displaying the ID number, it displays the name. Part of the formula in each of these reports is a list of IF-THEN statements, such as:
Code:
"IF{CLIENT.Partner}="112" THEN "Original" ELSE
"IF{CLIENT.Partner}="113" THEN "CheskiChips" ELSE " "
The problem is that whenever we hire a new employee, each report has to be updated so that these reports are pulling the correct information for current employee numbers. What I would like to do is change the code so that it refers to an external file containing code for employee ID references, with the goal of updating the external file once instead of updating dozens of reports.

8. CheskiChipsBannedBanned

Messages:
3,538
Okay...so it's been a looong time since I programmed in VB, I'll present you the Java code line which should give you an idea of how you can do it internally. How you store it to an external file (I didn't read that until after I wrote this) I will post some time later tonight after I finish my work load for the day.

The information in CLIENT.Partner seems to be held in a String...so I will maintain that protocol.

I also am unsure of how the THEN is simply a string and not a command, in any case it could be programmed in this fashion.
Code:
//   Builds an array that stores all of the Partner values.
String[] PartnerNumber = new String[NumberofPartners];
String ReturnedStringVal = "";

//  Gives two examples of the Strings stored in the array.
PartnerNumber[112]="Original";
PartnerNumber[113]="CheskiChips";

//   I assume CLIENT.Partner is sending a String value, I parse that value into an integer and then use it as the array assignment value in the previously initialized array.
ReturnedStringVal = PartnerNumber(Integer.parseInt(CLIENT.Partner));

//////////////////////////////////////

9. domesticated omStickler for detailsValued Senior Member

Messages:
3,277
My vb is gittin' kinda rusty too :/

Code:

Dim employee_name As String
Select Case CLIENT.Partner
case 112
employee_name = "Original"
case 113
employee_name = "CheskiChips"
case else
employee_name = "Unknown User"
End Select
MsgBox(employee_name)


I'm feeding these into messageboxes because I don't know what you are trying to feed the results into

I guess this would be useful if the only thing the CLIENT.Partner method does is spit out an integer value, and the only thing that needed to happen was it spat out the associated string value from a pre-existing list.
......in which case, the array would do the exact same thing.....

Code:

Dim employee_roster(113) As String
employee_roster(112) =  "Original"
employee_roster(113) = "CheskiChips"
If employee_roster(CLIENT.Partner) <> "" Then
Msgbox(employee_roster(CLIENT.Partner))
Else
Msgbox("Employee number " & CLIENT.Partner & " doesn't exist!")
End If


10. CheskiChipsBannedBanned

Messages:
3,538
original, Keep in mind that judging from the original source code - 'CLIENT.partner' appears to be a string value so it would have to be parsed into an int.