|
If you want to be case insensitive, create a new string by calling ToLower on the one you have, and then compare to all lower case strings. Or there's a case insensitive compare method, but I always do the lower case string, it's surely more efficient ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
If I can't find a neater alternative to nested if statements then I'll look into that option... Anything that is more efficient and helps speed up the process is more than welcome
|
|
|
|
|
Try a test on strSearchName.Length and an if statement
If strCombined.Length = 0 and strCombined.IndexOf("Cambridge University") Then<br />
strSearchName = "Cambridge University"<br />
end if<br />
If strCombined.Length = 0 and strCombined.IndexOf("xxxx") Then<br />
strSearchName = "xxxx"<br />
end if
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How could a zero length string contain "Cambridge University"?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
This may not necessarily be more efficient, but it is a little more elegant, and it is easier to maintain in case you need to use more than the three values from your example:
Dim strSearchName As String = ""
Dim Values() As String = {"Cambridge University", "FM Towns", "Jupiter Cantab"}
For Each v As String In Values
If strCombined.IndexOf(v) Then strSearchName = v
Next
By setting strSearchName to be an empty string beforehand, it will be your default value if the loop doesn't assign it a value.
The array I used here enables you to use a settings file, or database table, or something like that. In case the amount of values you need to monitor grows really large, you can easily replace it with some other method of creating a collection of strings (DataTable, DataReader, etc.)
Using a loop here enables you to easily incorporate operations like String.ToLower, etc. or to perform other actions on strSearchName or strCombined, while you are at it.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I agree that this is the more maintainable solution.
Just some corrections to the code...
The IndexOf method returns an integer, not a boolean.
You want to exit from the loop as soon as you have found a string, otherwise the code doesn't do the same as the original code.
Dim strSearchName As String = ""
Dim Values() As String = {"Cambridge University", "FM Towns", "Jupiter Cantab"}
For Each v As String In Values
If strCombined.IndexOf(v) <> -1 Then
strSearchName = v
Exit For
End If
Next
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you both for this option... It's definitely better than using the nested if...then...else statements... Should work nicely... Thanks again...
|
|
|
|
|
Hi all...
I am creating a program for a small company to store all informations about its product.
There are several branches of company in many cities. So this program will be used in several cities.
The main job I have to do is, if a person in city1 or city2 sell a product and print its bill, then that program will send all informations of that product(name,price,qty,date of purchasing and selling etc.) to the main program running on the system of manager of the company(in another city).
Please suggest me how can I do this...
Thanks.
Gagan
|
|
|
|
|
Sounds like another rentacoder job gone bad to me.....
Obviously you need a central database to manage this, and then I would say that a webservice you can call to report a sale is what you're after.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
can u tell me how can I use webservice call to send information.
Gagan
|
|
|
|
|
Well, you do it by calling the webservice. I assume you have no idea what a webservice is, did you google it and read up on what I'm talking about ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME:
'
' AUTHOR: OEM USER , OEM USER
' DATE : 12/15/2008
'
' COMMENT:
'
'==========================================================================
'Option Explicit
Dim strComputer, passLen, accName, inputFile, newpass
'-----------------------------------
passLen = 128
accName = "itdadmin"
strComputer = "."
'inputFile = strComputer
inputFile = "C:\COMPUTERS.TXT"
'-----------------------------------
newpass = generatePassword(passLen)
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("c:\windows\system32\pspasswd.exe @" &chr(34) &inputFile &chr(34) &" " &accName &" " &newpass )
'Set objWshScriptExec = objShell.Exec("c:\windows\system32\pspasswd.exe @" &chr(34) &strComputer &chr(34) &" " &accName &" " &newpass )
'Set objStdOut = objWshScriptExec.StdOutstrOutput = objStdOut.ReadAll
WScript.Echo date & "," & time & VbCrLf&"NewPassword: "& newpass& vbCrLf& vbCrLf & strOutput
Set objShell = Nothing
wscript.quit
Function generatePassword(PASSWORD_LENGTH)
Dim NUMLOWER, NUMUPPER, LOWERBOUND, UPPERBOUND, LOWERBOUND1, UPPERBOUND1, SYMLOWER, SYMUPPER
Dim newPassword, count, pwd
Dim pCheckComplex, pCheckComplexUp, pCheckComplexLow, pCheckComplexNum, pCheckComplexSym, pCheckAnswer
NUMLOWER = 48 ' 48 = 0
NUMUPPER = 57 ' 57 = 9
LOWERBOUND = 65 ' 65 = A
UPPERBOUND = 90 ' 90 = Z
LOWERBOUND1 = 97 ' 97 = a
UPPERBOUND1 = 122 ' 122 = z
SYMLOWER = 33 ' 33 = !
SYMUPPER = 46 ' 46 = .
pCheckComplexUp = 0 ' used later to check number of character types in password
pCheckComplexLow = 0 ' used later to check number of character types in password
pCheckComplexNum = 0 ' used later to check number of character types in password
pCheckComplexSym = 0 ' used later to check number of character types in password
' initialize the random number generator
Randomize()
newPassword = ""
count = 0
DO UNTIL count = PASSWORD_LENGTH
' generate a num between 2 and 10
' if num < 5 create an uppercase
If Int( ( 10 - 2 + 1 ) * Rnd + 2 ) < 5 Then
pwd = Int( ( UPPERBOUND - LOWERBOUND + 1 ) * Rnd + LOWERBOUND )
' if num is between 4 and 7 create a lowecase
Elseif Int( ( 10 - 2 + 1 ) * Rnd + 2 ) > 3 And Int( ( 10 - 2 + 1 ) * Rnd + 2 ) < 8 Then
pwd = Int( ( UPPERBOUND1 - LOWERBOUND1 + 1 ) * Rnd + LOWERBOUND1 )
' if num is between 8 and 10 generate a symbol
Else
pwd = Int( ( SYMUPPER - SYMLOWER + 1 ) * Rnd + SYMLOWER )
End If
newPassword = newPassword + Chr( pwd )
count = count + 1
'Check to make sure that a proper mix of characters has been created. If not discard the password.
If count = (PASSWORD_LENGTH) Then
For pCheckComplex = 1 To PASSWORD_LENGTH
'Check for uppercase
If Asc(Mid(newPassword,pCheckComplex,1)) >64 And Asc(Mid(newPassword,pCheckComplex,1))< 90 Then
pCheckComplexUp = 1
'Check for lowercase
ElseIf Asc(Mid(newPassword,pCheckComplex,1)) >96 And Asc(Mid(newPassword,pCheckComplex,1))< 123 Then
pCheckComplexLow = 1
'Check for numbers
ElseIf Asc(Mid(newPassword,pCheckComplex,1)) >47 And Asc(Mid(newPassword,pCheckComplex,1))< 58 Then
pCheckComplexNum = 1
'Check for symbols
ElseIf Asc(Mid(newPassword,pCheckComplex,1)) >32 And Asc(Mid(newPassword,pCheckComplex,1))< 47 Then
pCheckComplexSym = 1
End If
Next
'Add up the number of character sets. We require 3 or 4 for a complex password.
pCheckAnswer = pCheckComplexUp+pCheckComplexLow+pCheckComplexNum+pCheckComplexSym
If pCheckAnswer < 3 Then
newPassword = ""
count = 0
End If
End If
Loop
'The password is good so return it
generatePassword = newPassword
End Function
|
|
|
|
|
bohicamaster wrote: How can I target the local system instead of using a txt file for a Ramdom Password Change to all computer system
Uhhh... what? I don't understand what you're trying to do. You're going to have to explain the process you're using, why you're using files, and why you want to "target the local system". What does "target the local system" mean?? What are you ultimately trying to do with this??
|
|
|
|
|
How can this ever be rated a "good answer"? it is nothing but more questions
|
|
|
|
|
Is there anything that I missed? I wanted to make sure there no doubt that I had no idea what he was trying to do. What do you think?
|
|
|
|
|
Dave Kreskowiak wrote: Is there anything that I missed?
You sure didn't miss another opportunity to ask more questions...
|
|
|
|
|
I have the following code that groups a generic List(Of T) that I want to order by IMRecord.BusinessUnit, but I can't get it to work. Can anyone help me with this?
Dim query = From IMRecord In ImRecordList _
Group By IMRecord.BusinessUnit, _
IMRecord.DocType, _
IMRecord.Description, _
IMRecord.VendorCode, _
IMRecord.DocDate, _
IMRecord.PONumber, _
IMRecord.DocNumber, _
IMRecord.Account _
Into Group, Purchases = Sum(CDec(IMRecord.Purchases)), _
Debit = Sum(CDec(IMRecord.Debit)), _
Credit = Sum(CDec(IMRecord.Credit)) _
Order By IMRecord.BusinessUnit
If I take off the Order By the grouping works ok.
|
|
|
|
|
Looks like the into is in the wrong place. SQL format (assuming that's being used?):
select
into
from
where
group by
order by
cheers!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Is it possible to create and instantiate a VB6 .dll in VB .Net without having a reference to the VB6 .dll? I tried to use the Assembly.LoadFrom method, which doesn't seem to work (and probably isn't intended for ActiveX .dlls).
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Can you just create an assembly with the name VB6.dll?
|
|
|
|
|
Uhhh... WHAT??
|
|
|
|
|
I love these forums. Sorry Dave, but I have to say, the VB one is the worst. People with no idea trying to answer questions, I assume b/c they think a CP MVP would help them get a job.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: I love these forums. Sorry Dave, but I have to say, the VB one is the worst. People with no idea trying to answer questions,
No kidding. Over the last 5 years, I've watched the quality of questions just plummet, most likely due to the outsourcing boom. Now, those same people think less than a years experience makes them qualified to write articles and answer questions.
This is why I don't trust anything I read on the web any more!
|
|
|
|
|
Yeah, I am sure that outsourcing is the problem. I am sure people are hired in parts of the world and given a desk, a PC, and the URL to our forums.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: I am sure people are hired in parts of the world and given a desk, a PC, and the URL to our forums.
After dealing with a few of these companies, I <seriously>wouldn't be surprised!</seriously>
|
|
|
|
|