-
[RESOLVED] Writing (advanced?) functions?
There are functions provided within VB that let you do things like uniq([a-z])...by that I mean putting "[a-z]" rather than having to enclose in speech marks. If I was currently to make a function like this, I would have to use uniq("[a-z]") and parse the info within the speech marks, but I am wondering if there's any way around this :-)
-
Re: Writing (advanced?) functions?
What do you mean by "speech marks" ? do you mean quotes ?
I think you might refraze your question, becasue I don't understand anything from what you are saying there...
-
Re: Writing (advanced?) functions?
A speech mark is a "...a quotation mark...a double of '
Normally when I send a string in a function I would need to enclose the string within these speech marks thus: uniq("[a-z]")
I would like to know if there's any way to do it thus: uniq([a-z])
I think I made the original question clear enough, personally :-P
-
Re: Writing (advanced?) functions?
Quote:
Originally Posted by smUX
A speech mark is a "...a quotation mark...a double of '
Normally when I send a string in a function I would need to enclose the string within these speech marks thus: uniq("[a-z]")
I would like to know if there's any way to do it thus: uniq([a-z])
I think I made the original question clear enough, personally :-P
Believe me, your second post was MUCH clearer. :thumb:
As for whether you can do that or not, I don't believe you can. The reason there are quotes around the parameter being sent in, is because it is a string field. If it were accepting a number, using uniq(1) would work fine.
Trying to throw a string in without quotes would create an error while parsing the code, as the compiler would try to find the variable associated with the value you're trying to add in.
HTH
-
Re: Writing (advanced?) functions?
im with CVMichael - that first post was confusing.. ;) lol
but now it makes sense....
well.. the closest thing I think u could do would be to create a const or an enum..
VB Code:
Public Const az = "[a-z]"
or if u use the enum u can pick it from a list...
VB Code:
Public Enum strPass
UpperA_Z = "[A-Z]"
Lowera_z = "[a-z]"
End Enum
Public Sub Test(passedin As strPass)
End Sub
-
Re: Writing (advanced?) functions?
Using a const could work, actually...do you see why I am trying to do it? I plan to be making a few functions and I want to make them as easy to use as normal VB functions...can't remember one off hand but I'm sure people know what I am on about :-)
-
Re: Writing (advanced?) functions?
then Use the ENUM ;)
that way when u type the function name u will get a dropdown of choices for the function - use that code i posted.. then type Test( and you'll see..
very conveinient
-
Re: Writing (advanced?) functions?
you can't do an Enum like that Static, it's an ENUMeration, not an ESTRINGeration ;)
-
Re: Writing (advanced?) functions?
:blush: uhhhh.. oops he he
sorry.. its early and i havent had enough coffee yet.
i'll go hide in the corner until im awake
"Pay no attention to the man behind the curtain!"
:blush:
-
Re: Writing (advanced?) functions?
Quote:
Originally Posted by smUX
Using a const could work, actually...do you see why I am trying to do it? I plan to be making a few functions and I want to make them as easy to use as normal VB functions...can't remember one off hand but I'm sure people know what I am on about :-)
Not me...
-
Re: Writing (advanced?) functions?
Quote:
Originally Posted by penagate
Not me...
sMux wants to create functions like that:
Debug.Print "Af23" Like "[A-Z][a-z]##"
But even this particular function requires quote marks.
I can't recall one that uses [a-z] without the quote marks, can you point to a specific one?
All I can think of is this:
VB Code:
Option Explicit
Dim StringsArr As Variant
Public Enum strPass
UpperA_Z = 1
Lowera_z = 0
End Enum
Public Sub Test(passedin As strPass)
Select Case StringsArr(passedin)
Case "[a-z]"
'..
Case "[A-Z]" ''CIRCULAR coding, convert to number, then
''conert to string again :\ useless
'..
End Select
End Sub
Private Sub Form_Load()
StringsArr = Array("[a-z]", "[A-Z]")
Test UpperA_Z
End Sub
Kinda useless, maybe I got you wrong?
-
Re: Writing (advanced?) functions?
No, I can't think of one offhand...I am almost sure I have seen them though...although LIKE sounds familiar enough to be it...maybe I'm mistaken :-)
-
Re: Writing (advanced?) functions?
No, it's syntatically impossible.
-
Re: Writing (advanced?) functions?
don't you mean 'syntactically' ;) - what a ridiculous word
-
Re: Writing (advanced?) functions?
Leave me alone, I'm not the forum spellchecker any more :(
-
Re: [RESOLVED] Writing (advanced?) functions?
Thank God :-P
And Bush, watch out, I'm a perfect speller and could point out your errors :-P
Worse still, I could point you to http://www.vbforums.com/showpost.php...64&postcount=8 and inform you that when you're mentioning someone's name in conversation like that you should have a comma both before and after the name :-P
-
Re: [RESOLVED] Writing (advanced?) functions?
i just like how hard syntactically is to pronounce
-
Re: [RESOLVED] Writing (advanced?) functions?
For the sake of argument I shall assume the first 'C' is silent.
-
Re: [RESOLVED] Writing (advanced?) functions?
Add a K after the C when speaking it...syn-tack-tick-ah-lee
-
Re: [RESOLVED] Writing (advanced?) functions?
I know how to pronounce it! :p
:lol:
-
Re: [RESOLVED] Writing (advanced?) functions?
I don't know why one would really like to do things like this, but...
VB Code:
Option Explicit
Private Enum LETTERS
[UC A to Z] = 0
[LC a to z] = 1
End Enum
Private Function Uniq(CaseType As LETTERS) As String
Select Case CaseType
Case [UC A to Z]
Uniq = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Case [LC a to z]
Uniq = "abcdefghijklmnopqrstuvwxyz"
End Select
End Function
Private Sub Form_Load()
Debug.Print Uniq([UC A to Z])
End Sub
Spooky.
Edit!
And if someone wants to complain about performance, then just make it an array:
VB Code:
Option Explicit
Private Enum LETTERS
[UC A to Z] = 0
[LC a to z] = 1
End Enum
Private Uniq(1) As String
Private Sub InitUniq()
Uniq([UC A to Z]) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Uniq([LC a to z]) = "abcdefghijklmnopqrstuvwxyz"
End Sub
Private Sub Form_Load()
InitUniq
Debug.Print Uniq([UC A to Z])
End Sub
And it works a lot faster.
-
Re: [RESOLVED] Writing (advanced?) functions?
Not quite what I had in mind (wanted to be able to use A-F, L-Z, etc) but I think I can work with that maybe :-)
-
Re: [RESOLVED] Writing (advanced?) functions?
You'd just have a biiiiig enumeration in that case :D
Anyways, what you're generally asking for is kind of a request for a new feature in VB6 language. And I don't see a big advantage in not having the quotes around a string. I'd rather just pass character codes instead of passing strings or some special variables, because handling them is much faster.
vbKeyA for A, vbKeyB for B...
-
Re: [RESOLVED] Writing (advanced?) functions?
Here is something to think about:
VB Code:
Option Explicit
Private Function Uniq(StartCode As KeyCodeConstants, EndCode As KeyCodeConstants) As String
Dim lngStep As Long, lngSize As Long, kccCurrent As Byte
Dim barTemp() As Byte, lngA As Long
If StartCode > EndCode Then
lngStep = -1
lngSize = StartCode - EndCode
Else
lngStep = 1
lngSize = EndCode - StartCode
End If
ReDim barTemp(lngSize + lngSize + 1)
kccCurrent = StartCode
For lngA = 0 To UBound(barTemp) - 2 Step 2
barTemp(lngA) = kccCurrent
kccCurrent = kccCurrent + lngStep
Next lngA
barTemp(lngA) = kccCurrent
Uniq = CStr(barTemp)
End Function
Private Sub Form_Load()
Debug.Print Uniq(vbKeyA, vbKeyD)
End Sub
-
Re: [RESOLVED] Writing (advanced?) functions?
Maybe it'll be nothing, maybe it'll be useful, I dunno. You might remember me mentioning that "pet project" I am planning. Currently I am thinking that it will be a graphical OS (in the style of Windows 3.11) with lots of new built in functions (basically just DLLs written specifically for it) that programmers for the OS could use :-)
The plan will be to make these functions freely available also, if I even bother to do it...I am sure I'll have a go...it's just a "bit of fun" to see what I can achieve with people's help and my own skills :-)