Hey all i am probably overthinking this but how can i check the textbox for either a 655 or 699 in the first 3 numbers in the textbox?
The current code i how now works but displays an error if (im guessing) it doesnt find the other number in the textbox as well:
If Microsoft.VisualBasic.Mid(txtNumber.Text, 1, 3) <> 655 Or Microsoft.VisualBasic.Mid(txtNumber.Text, 1, 3) <> 699 Then
'ERROR
end if
What would i be doing incorrectly?
David
Like so:
If Left(txtNumber.Text, 3) = "655" OrElse Left(txtNumber.Text, 3) = "699" Then
' good?
End if
Although it looks like you might want an error if it's not either one, in which case just wrap the two test above in paran's and put a Not before them.
First, you're going to want to use Left, not Mid if it's the first 3 characters.
Second, you're checking a string against an integer.
Third, you're checking if it's not those 3 characters when I'm guessing you want to check if they are equal, so you'll want to change that, as well.
try
If Mid(txtNumber.Text, 1, 3) <> "655" And Mid(txtNumber.Text, 1, 3) <> "699" Then
'Code
End If
Related
The code so far looks like this
For i = 0 To (Len(needed) - 1)
If key.Contains(needed(i)) = False Then
key = key + needed(i)
Else
End If
Within the else I would want to remove all occurrences of the substring key(i) from key except the first one. I could do this using a flag variable within a for loop to gain the location of this and simply replace that with "" however I have the entire alphabet and 3 other characters to check for. Is there a better method to do this???
If you wanted to replace any occurrence of a string except the first one, you could get a substring representing the the string after the first one, and run the replace then.
key.Substring(key.IndexOf(key(i)) + 1).Replace(key(i), "")
Hope this helps.
I want to make for ever "1" in the text box do this code.
Instead it wont just see if there's any 1's or 2's
I tried this:
select case text box
case "1"
'do code
case "2"
'do code
end select
so if i typed 132421
it would not run my code i put for 1 and 2 it has to be just a 1 or a 2 in the text
It sounds like you want your code to execute multiple times for each occurrence of the digit 1, 2, etc. This loop would accomplish that:
For Each digit as Char in MyTextbox.Text
If digit = "1" Then
' do code
Else If digit = "2"
' do code
End If
Next
I'm guessing you want it to run specific code for each instance of those numbers? Like Nate said.
You will need to do a loop to run through each character in the textbox.
For Each Letter as Char in Textbox1.Text
Select Case Letter
Case "1"
' Do Code
Case "2"
' Do Code
End Select
Next
If you typed 132421, it would loop 6 times, though using only ones and twos only 4 will activate any code in this example.
I have isolated the problem and simplified the code to the root cause. More frustrating is that this loop works elsewhere without this error.
If you see the comments in the sequence here, there are 6 cells in the middle of the loop that turn into 0, and then after this 6 cell gap of 0's the loop works. I did use a msgbox to confirm the values were there. For whatever reason rows 130-135 always read as 0 though.
For x = 1 To 140
Cells(3 + x, "AW").Value = 70
'MsgBox (Cells(3 + x, "AW").Value)
'MsgBox confirms the correct value
'rows 130-135 are always empty with 0
Next
Any help greatly appreciated - very stumped at such a simple thing!
it was a simple logical error that was nested inside:
For a = 1 To Number_of_CalcRows
Cells(137 + a, "AW").Value = TenkanCurrent
Next
The problem was that I has not declared the TenkanCurrent with a value.
Does anyone know how I can prevent users from entering more than one comma in a text field using an if statement? For example:
if txtWidth.text (contains more than one ",") then
MsgBox ("Please enter only one comma.")
Else ...
What should I put in the place of the first pair of brackets? The program I am making this for is Solidworks.
I have only just started programming and some of the terms are not very clear to me. If it is explained elsewhere and I havent searched properly I apologize.
If someone could help me that would be very nice.
Thank you in advance!
Rob
You can use the InStr() function twice :
if (InStr(1,txtWidth.Value,",") > 0 ) then
if (InStr(InStr(1,txtWidth.Value,",") + 1,txtWidth.Value,",") > 0) then
MsgBox ("Please enter only one comma.")
end if
end if
See here for more info on InStr.
I think you would need some nested if statements.
Something like this:
If input = "," Then
If numcommas = 0 Then
numcommas = 0
Else
'Don't allow input of character
End If
End If
You'll need to alter this a little bit in order to use it but this should get you started, or at least give you a geneeral idea of where to go.
This is a way to do it with just one if function:
If (Len(txtWidth.text) - Len(Replace(txtWidth.text, ",", ""))) > 1 Then
'Your Message'
End If
What this code does is it compares the length of your string with the length of your string, cleaned of all commas. So Len("Test,") would give back a length of 5 while Len(Replace("Test,",",","") returns 4 and by substracting those values you get the number of commas in your string.
I know this may sound trivial but I just can't find an answer to it.
I have a rdlc report in which I like to alternate row background color and for this I've used the following formula:
=iif(RowNumber(Nothing) Mod 2, "#e5e5e5", "White")
I also need to hide some rows and for this I use the following formula:
= Fields!MeanAeb.Value <> ""
where MeanAeb is a field in my report. My problem is that rowNumber also counts the hidden rows, so my table may have two consecutive rows with the same background. is there a way to take only visible rows into account?
So if anyone has the same problem, I have an answer;
in the Code section of your ReportProperties add the following
Dim customRowNumber as Integer = 0
Dim previousRowNumber as integer = 0
Function CustomRowCounter(conditionToTest as Boolean, rowNumbner as Integer) as Integer
if(conditionToTest and rowNumbner <> previousRowNumber)
customRowNumber = customRowNumber + 1
previousRowNumber = rowNumbner
end if
return customRowNumber
End Function
then on the background field in your column properties add this condition:
=iif(Code.CustomRowCounter(Fields!MeanAeb.Value="",RowNumber(nothing)) Mod 2, "#e5e5e5", "White")
this is nice because you can add any condition you like in place of Fields!MeanAeb.Value="". Just remember to use the inverse of the condition in your rowVisibility field, otherwise you may cause strange effects.
Oh and if you want a chess board look to your report just drop the previousRowNumber :)