Cannot individual add digits of number together in vba - vba

I want to be able to add together the individual digits of a 4 digit number, but it does not seem to work.
I am doing this purely in VBA code. The result is output to a worksheet.
I have extracted part of my code and put it into a separate macro to test it and still get the same result. It concatenates the digits together.
I have added in lots of msgbox lines to see what it is doing, but cannot work out why, in this case, the value of main is not added up into the intm variable.
The variables intd1 to intd4 get the values correctly, but when I try to add them together into intm, it just concatenates them together.
Sub AddDigits()
'
' Add individual digits of number together
'
Dim intd1, intd2, intd3, intd4, main, intm As Integer
main = 1234
intd1 = Left(main, 1)
MsgBox (intd1)
intd2 = Mid(main, 2, 1)
MsgBox (intd2)
intd3 = Mid(main, 3, 1)
MsgBox (intd3)
intd4 = Right(main, 1)
MsgBox (intd4)
intm = intd1 + intd2 + intd3 + intd4
MsgBox ("intm = " & intm & Chr(13) & _
"intd1 = " & intd1 & Chr(13) & _
"intd2 = " & intd2 & Chr(13) & _
"intd3 = " & intd3 & Chr(13) & _
"intd4 = " & intd4 & Chr(13))
End Sub

When you declare the variables the way you did, the first bit are all "variants", and VBA your use of Mid, Left, and Right are all string functions, so VBA coverts the variant to Strings:
If you dim your variables properly, you get the expected result:
Sub AddDigits()
'
' Add individual digits of number together
'
Dim intd1 As Integer, _
intd2 As Integer, _
intd3 As Integer, _
intd4 As Integer, _
main As Integer, _
intm As Integer
main = 1234
intd1 = Left(main, 1)
MsgBox (intd1)
intd2 = Mid(main, 2, 1)
MsgBox (intd2)
intd3 = Mid(main, 3, 1)
MsgBox (intd3)
intd4 = Right(main, 1)
MsgBox (intd4)
intm = intd1 + intd2 + intd3 + intd4
MsgBox ("intm = " & intm & Chr(13) & _
"intd1 = " & intd1 & Chr(13) & _
"intd2 = " & intd2 & Chr(13) & _
"intd3 = " & intd3 & Chr(13) & _
"intd4 = " & intd4 & Chr(13))
End Sub

In addition to the above answer, you can also convert the data type anywhere later in the code. To convert anything to int use Cint. Similarly for other type conversion you check the link
intm = CInt(intd1) + CInt(intd2) + CInt(intd3) + CInt(intd4)

Related

List FormatConditions of all controls on an Access form

Is it possible to list the conditional formatting of all controls on a form? I'd like to be able to list out all existing conditions so that I can generate code to add/remove the existing conditions. I have inherited some complex forms and want to know what I'm dealing with and then generate some code to toggle the conditional formatting in areas where it is slowing down navigating a continuous form.
This Excel VBA example shows a similar format I'd like to have for Access.
https://stackoverflow.com/a/52204597/1898524
Only textboxes and comboboxes have Conditional Formatting.
There is no single property that can be listed to show a control's conditional formatting rule(s). Each rule has attributes that can be listed. Example of listing for a single specific control:
Private Sub Command25_Click()
Dim x As Integer
With Me.tbxRate
For x = 0 To .FormatConditions.Count - 1
Debug.Print .FormatConditions(x).BackColor
Debug.Print .FormatConditions(x).Expression1
Debug.Print .FormatConditions(x).FontBold
Next
End With
End Sub
The output for this example:
2366701
20
False
These are attributes for a rule that sets backcolor to red when field value is greater than 20.
Yes, code can loop through controls on form, test for textbox and combobox types, determine if there are CF rules and output attributes.
With some inspiration from #June7's example and some code from an article I found by Garry Robinson, I wrote a procedure that answers my question.
Here's the output in the Immediate window. This is ready to be pasted into a module. The design time property values are shown as a comment.
txtRowColor.FormatConditions.Delete
txtRowColor.FormatConditions.Add acExpression, acBetween, "[txtCurrent_Equipment_List_ID]=[txtEquipment_List_ID]"
With txtRowColor.FormatConditions.Item(txtRowColor.FormatConditions.Count-1)
.Enabled = True ' txtRowColor.Enabled=False
.ForeColor = 0 ' txtRowColor.ForeColor=-2147483640
.BackColor = 10092543 ' txtRowColor.BackColor=11850710
End With
You can test this sub from a click event on an open form. I was getting some false positives when checking the Boolean .Enabled property, even when I store the values into Boolean variables first. I don't know why and am researching it, but that is beyond the scope of this question.
Public Sub ListConditionalFormats(frmForm As Form)
' Show all the Textbox and Combobox controls on the passed form object (assuming the form is open).
' Output the FormatCondtion properties to the immediate window in a format that is
' suitable to be copied into VBA to recreate the conditional formatting.
' The design property value is shown as a comment on each condition property row.
Dim ctl As Control
Dim i As Integer
Dim bolControlEnabled As Boolean
Dim bolFormatEnabled As Boolean
On Error GoTo ErrorHandler
For Each ctl In frmForm.Controls
If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
With ctl
If .FormatConditions.Count > 0 Then
'Debug.Print vbCr & "' " & ctl.Name, "Count = " & .FormatConditions.Count
For i = 0 To .FormatConditions.Count - 1
' Generate code that can recreate each FormatCondition
Debug.Print ctl.Name & ".FormatConditions.Delete"
Debug.Print ctl.Name & ".FormatConditions.Add " & DecodeType(.FormatConditions(i).Type) _
& ", " & DecodeOp(.FormatConditions(i).Operator) _
& ", """ & Replace(.FormatConditions(i).Expression1, """", """""") & """" _
& IIf(Len(.FormatConditions(i).Expression2) > 0, ", " & .FormatConditions(i).Expression2, "")
Debug.Print "With " & ctl.Name & ".FormatConditions.Item(" & ctl.Name & ".FormatConditions.Count-1)"
bolControlEnabled = ctl.Enabled
bolFormatEnabled = .FormatConditions(i).Enabled
'Debug.Print bolControlEnabled <> bolFormatEnabled, bolControlEnabled, bolFormatEnabled
If bolControlEnabled <> bolFormatEnabled Then ' <- This sometimes fails. BS 2/9/2020
'If ctl.Enabled <> .FormatConditions(i).Enabled Then ' <- This sometimes fails. BS 2/9/2020
Debug.Print vbTab & ".Enabled = " & .FormatConditions(i).Enabled; Tab(40); "' " & ctl.Name & ".Enabled=" & ctl.Enabled
End If
If ctl.ForeColor <> .FormatConditions(i).ForeColor Then
Debug.Print vbTab & ".ForeColor = " & .FormatConditions(i).ForeColor; Tab(40); "' " & ctl.Name & ".ForeColor=" & ctl.ForeColor
End If
If ctl.BackColor <> .FormatConditions(i).BackColor Then
Debug.Print vbTab & ".BackColor = " & .FormatConditions(i).BackColor; Tab(40); "' " & ctl.Name & ".BackColor=" & ctl.BackColor
End If
If ctl.FontBold <> .FormatConditions(i).FontBold Then
Debug.Print vbTab & ".FontBold = " & .FormatConditions(i).FontBold; Tab(40); "' " & ctl.Name & ".FontBold=" & ctl.FontBold
End If
If ctl.FontItalic <> .FormatConditions(i).FontItalic Then
Debug.Print vbTab & ".FontItalic = " & .FormatConditions(i).FontItalic; Tab(40); "' " & ctl.Name & ".FontItalic=" & ctl.FontItalic
End If
If ctl.FontUnderline <> .FormatConditions(i).FontUnderline Then
Debug.Print vbTab & ".FontUnderline = " & .FormatConditions(i).FontUnderline; Tab(40); "' " & ctl.Name & ".FontUnderline=" & ctl.FontUnderline
End If
If .FormatConditions(i).Type = 3 Then ' acDataBar
Debug.Print vbTab & ".LongestBarLimit = " & .FormatConditions(i).LongestBarLimit
Debug.Print vbTab & ".LongestBarValue = " & .FormatConditions(i).LongestBarValue
Debug.Print vbTab & ".ShortestBarLimit = " & .FormatConditions(i).ShortestBarLimit
Debug.Print vbTab & ".ShortestBarValue = " & .FormatConditions(i).ShortestBarValue
Debug.Print vbTab & ".ShowBarOnly = " & .FormatConditions(i).ShowBarOnly
End If
Debug.Print "End With" & vbCr
Next
End If
End With
End If
Next
Beep
Exit_Sub:
Exit Sub
ErrorHandler:
MsgBox "Error #" & Err.Number & " - " & Err.Description & vbCrLf & "in procedure ListConditionalFormats" _
& IIf(Erl > 0, vbCrLf & "Line #: " & Erl, "")
GoTo Exit_Sub
Resume Next
Resume
End Sub
Function DecodeType(TypeProp As Integer) As String
' You heed this are there are 4 different ways to setup a CondtionalFormat
' https://vb123.com/listing-conditional-formats
Select Case TypeProp
Case 0
DecodeType = "acFieldValue"
Case 1
DecodeType = "acExpression"
Case 2
DecodeType = "acFieldHasFocus"
Case 3
DecodeType = "acDataBar"
End Select
End Function
Function DecodeOp(OpProp As Integer) As String
' You need this becuase equations can comprise of = > <> between
' https://vb123.com/listing-conditional-formats
Select Case OpProp
Case 0
DecodeOp = "acBetween"
Case 1
DecodeOp = "acNotBetween"
Case 2
DecodeOp = "acEqual"
Case 3
DecodeOp = "acNotEqual"
Case 4
DecodeOp = "acGreaterThan"
Case 5
DecodeOp = "acLessThan"
Case 6
DecodeOp = "acGreaterThanOrEqual"
Case 7
DecodeOp = "acLessThanOrEqual"
End Select
End Function

An app operating under Windows 10 finds a byteOrderMarkUtf8 in a string, but there isn't one in the string

I have an app that receives an XML string and tries to clean it up before processing. For some reason, under the Windows 10 operating system, the app thinks there is a byteOrderMarkUtf8 leading the string. There isn't one.
The first character is "<". The app removes the "<", and then removes the rest of the tag, too, creating an invalid XML.
This used to work under Windows 7.
In the code below, I have commented the offending section out.
Is there something about character encoding that has changed with Windows 10 that would be causing this?
Private Sub CleanXML(ByRef InString As String)
' This subroutine cleans trash characters out of XML streams
If (InString = "") Then
MessageBox.Show("Null String passed to CleanXML." & vbCr & _
"String Length: " & InString.Length & vbCr & _
"Instring: " & InString & vbCr)
End If
If (InString.Length = 0) Then
MessageBox.Show("String of 0 length or null String passed to CleanXML." & vbCr & _
"String Length: " & InString.Length & vbCr & _
"Instring: " & InString & vbCr)
End If
Dim CleanString As String = InString
CleanString = CleanString.Trim() ' Trim leading and trailing spaces
CleanString = CleanString.Replace("- ", "") ' Replace the dashes
CleanString = CleanString.Replace(" <", "<") ' Replace some white space
CleanString = CleanString.Replace(" <", "<") ' Replace some white space
CleanString = CleanString.Replace("-<", "<") ' Replace dash+lessthan with lessthan
CleanString = CleanString.Replace("- <", "<") ' Replace dash+space+lessthan with lessthan
CleanString = CleanString.Replace("&", "&") ' Replace & with &
Dim Tempstring As String = ""
If CleanString.Length > 0 Then
Try
Dim byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble())
' This is the offending code that I have commented out.
'-------------------------------------------------------------
'If (CleanString.StartsWith(byteOrderMarkUtf8)) Then
' CleanString = CleanString.Remove(0, byteOrderMarkUtf8.Length)
'End If
'If (CleanString.EndsWith(byteOrderMarkUtf8)) Then
' CleanString = CleanString.Remove(CleanString.Length - 1, byteOrderMarkUtf8.Length)
'End If
'-------------------------------------------------------------
' Make sure the first and last characters are "<" and ">".
Tempstring = CleanString
Do Until (CleanString.StartsWith("<") Or (CleanString.Length = 0))
CleanString = CleanString.Remove(0, 1)
Loop
Do Until (CleanString.EndsWith(">") Or (CleanString.Length = 0))
CleanString = CleanString.Remove(CleanString.Length - 1, 1)
Loop
Catch ex As Exception
MessageBox.Show("Error in CleanXML." & vbCr & _
"String Length: " & CleanString.Length & vbCr & _
"Instring: " & InString & vbCr & _
"CleanString: " & CleanString & _
" Length: " & CleanString.Length.ToString)
MessageBox.Show(ex.Message + " Inner exception: " + ex.InnerException.Message)
MessageBox.Show(Tempstring)
End Try
Else
MessageBox.Show("Clean string of 0 length in CleanXML." & vbCr & _
"String Length: " & CleanString.Length & vbCr & _
"Instring: " & InString & vbCr & _
"CleanString: " & CleanString)
End If
' Remove any BOMs (Byte-Order Marks) from the string.
'Dim i As Integer = InStr(1, CleanString, byteOrderMarkUtf8)
'Do Until i = 0
' CleanString = CleanString.Remove(i - 1, byteOrderMarkUtf8.Length)
' i = InStr(i, CleanString, byteOrderMarkUtf8)
'Loop
InString = CleanString
End Sub

Run-Time Error 40046: Statement too complex

I'm trying to write a code module using the InsertLines method, but am getting the
Statement too complex Error
My code boils down to this loop:
Dim extractorModule As VBComponent
With extractorModule.codeModule
Dim singItem As codeItem
Dim i As Long
For i = LBound(codeItems) To UBound(codeItems)
singItem = codeItems(i) 'array of private type with .value property
.InsertLines 5, singItem.value 'write to line 5
Next i
End With
Which loops through an array of custom codeItems, and writes their .value to a new module with .InsertLines
singItem.value is a base64 encoded string. If it is a short one, 100 characters say, like this string:
.code_content = "QXR0cmlidXRlIFZCX05hbWUgPSAic2ltcGxlTW9kdWxlIg0KUHJpdmF0ZSBhIEFzIExvbmcNCg=="
no problem. However I want a longer string, this one for example (19000 chars, contains newlines):
.code_content = "QXR0cmlidXRlIFZCX05hbWUgPSAicHJvamVjdENvbXByZXNzb3IiDQonQ29tcHJlc3NvciBtb2R1bGUsIGNvbXByZXNzZXMgYSBsb2FkIG9mIGZpbGVzIGludG8gc3RyaW5ncyB0byBleHBvcnQNCk9wdGlvbiBFeHBsaWNpdA0KUHJpdmF0ZSBUeXBlIGNvZGVJdGVtDQogICAgZXh0ZW5zaW9uIEFzIFN0cmluZw0KICAgIG1vZHVsZV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wgIiINCi5JbnNlcnRMaW5lcyAxMTYsICIgICAgSWYgYjIgPSAwIFRoZW4iDQouSW5zZXJ0TGluZXMgMTE3LCAiICAgICAgICBPdXQoaiAtIDMpID0gKHYgKyA2NSkgXCA2NTUzNiINCi5JbnNlcnRMaW5lcyAxMTgsICIgICAgICAgIGogPSBqIC0gMiINCi5JbnNlcnRMaW5lcyAxMTksICIgICAgRWxzZUlmIGIzID0gMCBUaGVuIg0KLkluc2VydExpbmVzIDEyMCwgIiAgICAgICAgT3V0KGogLSAzKSA9ICh2ICsgMSkgXCA2NTUzNiINCi5JbnNlcnRMaW5lcyAxMjEsICIg" & _
"ICAgICAgIE91dChqIC0gMikgPSAoKHYgKyAxKSBcIDI1NiYpIE1vZCAyNTYiDQouSW5zZXJ0TGluZXMgMTIyLCAiICAgICAgICBqID0gaiAtIDEiDQouSW5zZXJ0TGluZXMgMTIzLCAiICAgIEVuZCBJZiINCi5JbnNlcnRMaW5lcyAxMjQsICIiDQouSW5zZXJ0TGluZXMgMTI1LCAiICAgIFJlRGltIFByZXNlcnZlIE91dChqIC0gMSkiDQouSW5zZXJ0TGluZXMgMTI2LCAiICAgIEZyb21CYXNlNjQgPSBPdXQiDQouSW5zZXJ0TGluZXMgMTI3LCAiRW5kIEZ1bmN0aW9uIg0KRGltIHJlc3VsdCgwIFRvIDEpIEFzIExvbmcNCklmIC5GaW5kKCJ7MH0iLCByZXN1bHQoMCksIHJlc3VsdCgxKSwgLTEsIC0xKSBUaGVuICdzZWFyY2ggZm9yIHBvaW50IHRvIGluc2VydCBsaW5lcw0KICAgIGZpbGxNb2R1bGUgPSByZXN1bHQNCkVsc2UNCiAgICByZXN1bHQoMCkgPSAwDQogICAgcmVzdWx0KDEpID0gMA0KICAgIGZpbGxNb2R1bGUgPSByZXN1bHQNCkVuZCBJZg0KRW5kIFdpdGgNCkVuZCBGdW5jdGlvbg0KDQoNCg0K"
According to the docs, linefeed character vbCrLf should just make code on separate lines (what I want), so that shouldn't be causing the error.
However the length of string is not the problem either, as if .value = String(19000,"a") I have no issues. What's the cause of this error and how do I get around it?
Update
Something more re-createable:
Sub testAdd()
Dim codeStuff As codeModule
On Error Resume Next
Set codeStuff = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_StdModule).codeModule
'check for vbProj access
If Err.Number <> 0 Then MsgBox "Access to VBProject disabled": Exit Sub
On Error GoTo 0
'try to add code
With codeStuff
Dim i As Long
For i = 1 To 3
'i = 1 fails for me
On Error Resume Next
.InsertLines 1, exampleString(i) 'causes the error
Debug.Print "Case"; i; IIf(Err.Number = 0, " suceeded", " failed with err:" & Err.Number)
On Error GoTo -1
Next i
End With
ThisWorkbook.VBProject.VBComponents.Remove codeStuff.Parent
End Sub
Function exampleString(stringType As Long) As String
Dim result As String
Select Case stringType
Case 1 'lots of linefeed
Dim bit As Long
For bit = 1 To 19
result = result & """" & String(1000, "a") & """ & _" & vbCrLf
Next bit
result = result & """" & String(1000, "a") & """"
Case 2 'long string
result = String(20000, "a")
Case Else 'short string
result = String(100, "a")
End Select
exampleString = result
End Function
There is a limit of "prolonging" lines with _ at the end, try building your string part by part:
.code_content = "first part"
.code_content = .code_content & "second part"

I am trying to write a program in VBA that when a document is open a message box will appear that asks for user input to continue.?

In this box it will say what document was opened, the last version that you read of it, and the current up to date version of the document. The documents are named differently and are separated by 3 factors: an example of this would be QRS-RTY-006.G.docm, where QRS-RTY- is the same for all the documents, 006.G is the portion where you tell what version is available that I need to use to identify the current and last read version, and the .docm stays the same for each document.
Current Code:
Dim A As String
Dim B As String = Name
Dim C As String
Dim D As String = Name
A = Split(B, "_")(0)
C = Split(D, "_")(1)
MsgBox("You have opened " & A & " Revision " & C & " . The last revision you read was ___. The current revision is ___. Would you like to compare? ", vbYesNo)
If vbYes Then
End If
This should be a good start :
Private Sub Document_Open()
Dim dName As String, _
dVersion As String, _
mAnswer As Integer, _
SrcFile As String, _
PossFiles As String
dName = Left(ActiveDocument.Name, 7)
dVersion = Right(Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 5), 5)
mAnswer = MsgBox("You have opened : " & dName & ", Revision : " & dVersion & "." & Chr(13) & _
"The last revision you read was ___." & Chr(13) & _
"The current revision is " & dVersion & Chr(13) & _
Chr(13) & Chr(13) & "Would you like to compare? ", vbYesNo)
If mAnswer <> vbYes Then
'vbNo : They don't want to compare
Else
'vbYes : They want to compare
scrFile = Dir(ActiveDocument.Path & "\" & dName & "*.docm")
Do While scrFile <> ""
PossFiles = PossFiles & Dir & Chr(13)
scrFile = Dir
Loop
If PossFiles <> vbNullString Then
MsgBox PossFiles
Else
MsgBox "No other files found"
End If
End If
End Sub

Can't get the tabs value (name) in VBA macro

I'm stuck here. below is my vba macro. I want to lookup againts other tabs but the result only give me
=VLOOKUP(BE2, $BQ$2:$BQ$6, 1, 0) but not the tabs name.. Why? How can I get the sheets name?
Set myValues = Application.InputBox("Please select a:", Type:=8)
Set myResults = Application.InputBox("Please select a next sheet:", Type:=8)
On Error Resume Next
Set myValues = myValues.Offset
FirstRow = myValues.Row
FinalRow = Cells(65536, myResults.Column).End(xlUp).Row
Range("BF2").Formula = _
"=VLOOKUP(" & Cells(FirstRow, myValues.Column).Address(False, False) & ", " & _
" " & myResults.Address & " , 1, 0)"
You're close. You just need to set the Address External argument to True.
Something like:
myResults.Address(External:=True)
The .Address property only returns the row and column reference unless you set the External parameter to True. See below:
Range("BF2").Formula = _
"=VLOOKUP(" & Cells(FirstRow, myValues.Column).Address(False, False) & ", " & _
" " & myResults.Address(External:=True) & " , 1, 0)"
If you don't want the workbook name in the reference, you can build the reference using the .Worksheet.Name property of the Range object. See below:
Range("BF2").Formula = _
"=VLOOKUP(" & Cells(FirstRow, myValues.Column).Address(False, False) & ", " & _
" " & myResults.Worksheet.Name & "!" & myResults.Address & " , 1, 0)"
See the Range.Address Property on MSDN for more information.