Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Command Make it a Variable ie Get From Textbox 1

Status
Not open for further replies.

Trob70

Programmer
Sep 25, 2012
89
AU

??is it possible to make a case statement using a value from a form textbox

ie Contains eg Case 49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:

This the present code..all working fine
Select Case Asc(Mid(strSource, i, 1))

Case 49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:

------------------------


Can I do this.....
Text1.Text =" 49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:"
I want to be able to alter the case at Runtime without altering the VB Code


Select Case Asc(Mid(strSource, i, 1))

Case (Text1.Text)


Appreciate any help...!!


Regards Robert




 
Hi,
Code:
Select Case Text1.Text
   Case "49", "57", "63", "45", "39", "32", "48" To "57", "65" To "90", "97" To "122"

   Case Else

End Select


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Sorry I May not have made my question real clear...

This is my Current code

Function AlphaNumericOnlysss(strSource As String) As String

Dim i As Integer
Dim strResult As String

For i = 1 To Len(strSource)

Select Case Asc(Mid(strSource, i, 1))

Case 49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:

strResult = strResult & Mid(strSource, i, 1)
End Select

Next
AlphaNumericOnly = strResult

End Function

I need to be able to alter the 49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:
at runtime with whatever has been typed into text1.text on the form

eg

Select Case Asc(Mid(strSource, i, 1))

Case (Text1.text)



Regards Robert





 
So then why would you need ANY Case or If statement to TEST the input values?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 

What I am trying to do is as follows

49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:
Alter it to say 32, 48 To 57, 65 To 90, 97 To 122: (or whatever) AT RUNTIME
ie. ADJUSTABLE ...Without having to actually alter the source code and recompile

I Have looked allover the forums and have seen nothing in this area

eg Case "Red", "Green", "Yellow"
??What if i need to alter it to "White", "Black","Red", "Green", "Yellow"
Just for 1 instance



** I am beginning to think i will just do an IF statement in code ,using adjustable values entered on the FORM



Regards Robert
 
Are you saying that you need to ADD additional values, to the existing values,

OR

Are you saying that these new set of values will REPLACE the existing values?

Either way, use a Table of values that you can either ADD new values to or DELETE existing values and ADD new values. Then loop thru the table to compare.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Thanks for your interest

I need to REPLACE the existing values
BUT if its easier to achieve Add would do..

ie Have say 49, 57, 63, 45, 39, 32, 48 To 57, 65 To 90, 97 To 122:
in a text box on the form


alter the form textbox to say 32, 48 To 57, 65 To 90, 97 To 122:
Select Case Asc(Mid(strSource, i, 1))
and the program uses this new value Case Textbox1



Regards Robert



 
What a tedious effort to type into a textbox a series of values!

Is that the best approach from a users' perspective?

What's the business case for this?

BTW, what's a typical value for strSource?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
SkipVought (Programmer)

Sorry to cause so much fuss about this question

I was just interested IF eg Case 97 To 122
That is hard wired into the code could be varied at runtime.
I looked all over internet and found no mention or anyone achieving this.
I have finally worked out how to do it
f1 = "97"
f2 = "122"
I can make f1 and f2 public variables or parameters
If I put brackets around f1 and f2 it works

For i = 1 To Len(strSource)
Select Case Asc(Mid(strSource, i, 1))
Case (f1) To (f2)
strResult = strResult & Mid(strSource, i, 1)
End Select
Next

Many thanks for your interest in looking at this

You have helped me many times before , many thanks


Robert

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top