Design advice

D

dthmtlgod

I am creating a online help desk for my office. I am attempting to cleanup
my code and I was hoping for a little advice.

I have 30 different categories of requests ranging from the desktop issues
to application issues. I am using submit buttons on one version and a
dropdown/list box on the other. Both work the same.

All the items have the same name "cmdProblem". The value is then passed to
another form. This all works great.

I then have 30 "if" statements that ask a series of questions. A lot of
them ask the same questions, a few differ though. There is 1,800 lines of
code. Is there an easier way to do this?

PT = request.form("cmdProblem")

<% if ucase(pt) = "MONITOR" then %>

..... Code ....

I do this 30 times.
 
M

McKirahan

dthmtlgod said:
I am creating a online help desk for my office. I am attempting to cleanup
my code and I was hoping for a little advice.

I have 30 different categories of requests ranging from the desktop issues
to application issues. I am using submit buttons on one version and a
dropdown/list box on the other. Both work the same.

All the items have the same name "cmdProblem". The value is then passed to
another form. This all works great.

I then have 30 "if" statements that ask a series of questions. A lot of
them ask the same questions, a few differ though. There is 1,800 lines of
code. Is there an easier way to do this?

PT = request.form("cmdProblem")

<% if ucase(pt) = "MONITOR" then %>

.... Code ....

I do this 30 times.


If I understand the issue ...

You could have a matrix defining which problem asks which questions;
then, for the given Problem, ask the associated questions. For example:

Dim arrP(30) '= Problems
arrP(1) = "Monitor"
arrP(2) = "Keyboard"
...
Dim booP
booP = False
Dim intP
Dim strP

Dim arrQ(10) '= Questions
arrQ(1) = "Size?"
arrQ(2) = "Resolution?"
arrQ(3) = "O/S?"
...

Dim arrX(20) '= Problem / Question Matrix
arrX(1) = "1,2"
...

Dim arrY
Dim intY
Dim strY

Dim Problem
Problem = Request.Form("Problem")

For intP = 1 To UBound(arrP)
If arrP(intP) = Problem Then
booP = True
Exit For
End If
Next

If booP Then
arrY = Split(arrX(intP),",")
strY = "Please answer the following questions about your '"
strY = strY & arrp(Problem) & "' problem:" & vbCrLf
For intY = 0 To UBound(arrY)
strY = strY & vbCrLf & arrQ(arrY(intY))
Next
Response.Write(strY)
Else
Response.Write("Invalid Problem! (" & Problem & ")")
End If


[ P.S. I know arrays are zero-based.]
 
D

dthmtlgod

Wow, thank you for this, I will give it a try. I should be able to figure
this out. I am horrible with arrays though.

What does the booP variable accomplish?


McKirahan said:
dthmtlgod said:
I am creating a online help desk for my office. I am attempting to cleanup
my code and I was hoping for a little advice.

I have 30 different categories of requests ranging from the desktop issues
to application issues. I am using submit buttons on one version and a
dropdown/list box on the other. Both work the same.

All the items have the same name "cmdProblem". The value is then passed to
another form. This all works great.

I then have 30 "if" statements that ask a series of questions. A lot of
them ask the same questions, a few differ though. There is 1,800 lines of
code. Is there an easier way to do this?

PT = request.form("cmdProblem")

<% if ucase(pt) = "MONITOR" then %>

.... Code ....

I do this 30 times.


If I understand the issue ...

You could have a matrix defining which problem asks which questions;
then, for the given Problem, ask the associated questions. For example:

Dim arrP(30) '= Problems
arrP(1) = "Monitor"
arrP(2) = "Keyboard"
...
Dim booP
booP = False
Dim intP
Dim strP

Dim arrQ(10) '= Questions
arrQ(1) = "Size?"
arrQ(2) = "Resolution?"
arrQ(3) = "O/S?"
...

Dim arrX(20) '= Problem / Question Matrix
arrX(1) = "1,2"
...

Dim arrY
Dim intY
Dim strY

Dim Problem
Problem = Request.Form("Problem")

For intP = 1 To UBound(arrP)
If arrP(intP) = Problem Then
booP = True
Exit For
End If
Next

If booP Then
arrY = Split(arrX(intP),",")
strY = "Please answer the following questions about your '"
strY = strY & arrp(Problem) & "' problem:" & vbCrLf
For intY = 0 To UBound(arrY)
strY = strY & vbCrLf & arrQ(arrY(intY))
Next
Response.Write(strY)
Else
Response.Write("Invalid Problem! (" & Problem & ")")
End If


[ P.S. I know arrays are zero-based.]
 
M

McKirahan

dthmtlgod said:
Wow, thank you for this, I will give it a try. I should be able to figure
this out. I am horrible with arrays though.

What does the booP variable accomplish?

I use hungarian notation (sort of) for variable name prefixes:

obj = object
int = integer (well, numeric anyway)
str = string
boo = boolean (i.e. True/False)

booP (if True) indicates that the Problem was found in arrP().
 
D

dthmtlgod

Thanks, make sense now.


McKirahan said:
I use hungarian notation (sort of) for variable name prefixes:

obj = object
int = integer (well, numeric anyway)
str = string
boo = boolean (i.e. True/False)

booP (if True) indicates that the Problem was found in arrP().
 
D

dthmtlgod

Getting very close to getting this to work. I am getting a Type Mismatch
Error, if I select a valid problem, works great if I select a problem not
listed.

Dim ArrP(3) '=Problems
arrP(1) = "TOWER"
arrP(2) = "MONITOR"
arrP(3) = "KEYBOARD"

Dim booP
booP = False

Dim intP
Dim strP

Dim arrQ(3) '=Questions
arrQ(1) = "Is it broke?"
arrQ(2) = "Type of hardware?"
arrQ(3) = "Any other info?"

Dim arrX(3) '=Problem/Questions
arrX(1) = "1,2,3"
arrX(2) = "2,3"
arrX(3) = "1,3"

Dim arrY
Dim intY
Dim strY

Dim Problem
Problem = request.form("cmdProblem")

For intP = 1 to UBound(arrP)
if arrP(intP) = Problem then
booP = true
exit for
end if
next

if booP then
arrY = Split(arrX(inpP), ", ")
strY = "Please answer the following questions about your '"

**** Getting it on this line
strY = strY & arrP(Problem) & "' problem: " & vbCrLF
*****
for intY = 0 to UnBound(arrY)
strY = strY & vbCrLF & arrQ(arrY(intY))
next
Response.write (strY)
else
response.write ("Invalid Problem (" & Problem & ")")
end if

%>
 
D

dthmtlgod

Typos on my part mostly. I think I have it where it is workable. Thank you
again for your script.
 
D

dthmtlgod

It is asking the questions as it should, it is not displaying the problem
though. Still getting a type mismatch error. Any ideas?

Dim ArrP(3) '=Problems
arrP(1) = "TOWER"
arrP(2) = "MONITOR"
arrP(3) = "KEYBOARD"

strY = "Please answer the following questions about your '"
**** Getting it on this line
strY = strY & arrP(Problem) & "' problem: " & vbCrLF
****
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,413
Latest member
ReeceDorri

Latest Threads

Top