How Can I join a String "" with a Value in VBA powerpoint - vba

So I have this textbox and a string I want to set a label to the string and the value combined like this:
Lebel1.Caption = "Hello" Textbox1.Text
I don't know what the proper code is.

I guess you are having a Typo issue. Not sure if your control is Lebel or Label.
In this example you can combine a predefined Text and a Control text or Variable. Don't forget to add an space after your words.
Label1.Caption = "Hello " & Textbox1.Text & "."
Label1.Caption = "Hello " & Your variable & "."
Also you can add a line break and also use a Message Box as follows:
Msgbox = "Welcome Message." & Chr(10) & "Hello " & Textbox1.Text & "."

Related

vb.net find and replace text inside a textbox in Word

I have this line of code which does a search and replace in a word document:
oDoc.Content.Find.Execute(FindText:="Invoice", ReplaceWith:="Invoice - Paid: " + paid_date, Replace:=word.WdReplace.wdReplaceAll)
Is there any way, i can do the search and replace inside a specific textbox in word rather than the whole document?
Here is one way to go about it.
For Each oCtl As Shape In doc.Shapes
If oCtl.Type = Microsoft.Office.Core.MsoShapeType.msoTextBox Then
oCtl.TextFrame.TextRange.Text.Replace("Invoice", "Invoice - Paid: " + paid_date)
End If
Next
This essentially searches all the text boxes in your document and replaces "Invoice"
As an attempt to find the name of the textbox try this...
For Each oCtl As Shape In doc.Shapes
If oCtl.Type = Microsoft.Office.Core.MsoShapeType.msoTextBox Then
MsgBox("Name: " & oCtl.Name & vbNewLine & "ID: " & oCtl.ID & vbNewLine & "Title: " & oCtl.Title & vbNewLine & "Text: " & oCtl.TextFrame.TextRange.Text)
End If
Next
This should give you unique or identifiable items of every textbox.
then you could just go like this -
If oCtl.Name = "1234" then oCtl.Text.replace(whatever)
or ID or Title or whatever you decide to choose.

VBA adding a list empty fields from a userform to a message box

I have created a userform that requires the user to input several strings or integers. I am trying to get a message box come up if several of the mandatory boxes are not filled in. I want to list the empty fields but skip the fields that are filled in. I know how to do a for loop if the values were integers but most of the inputs are strings. I think I could do something with Dim C as control, and I know the general layout of my message box, but I am stumped beyond that. Please help so that I don’t have to write six separate conditional statements with six separate message boxes!
The six form field names are:
Proposal_Name, Date_of_Submission, cboContraact_type, Contract_Neg_Name, Contract_Neg_Number, and Validity_Period
The general layout of the message box I had in mind is as follows:
MsgBox "You have left the following mandatory fields empty:" & vbCrLf & vbCrLf & "Proposal_Name" & vbNewLine & "Date_of_Submission" & Chr(10) & "cboContraact_type" & Chr(10) & "Contract_Neg_Name" & Chr(10) & "Validity_Period"
Since you are only concerned about 6 fields, I would not go down the path of looping through the form controls, determining the control type, checking for missing value, etc.
Here is an OnClick for a Command Button that might work for you:
Private Sub Command12_Click()
Dim sMissingValues As String
sMissingValues = ""
If Nz(Me!Proposal_Name, "") = "" Then sMissingValues = sMissingValues + vbCrLf + "Proposal_Name"
If Nz(Me!Date_of_Submission, "") = "" Then sMissingValues = sMissingValues + vbCrLf + "Date_of_Submission"
If Nz(Me!cboContraact_type, "") = "" Then sMissingValues = sMissingValues + vbCrLf + "cboContraact_type"
If Nz(Me!Contract_Neg_Name, "") = "" Then sMissingValues = sMissingValues + vbCrLf + "Contract_Neg_Name"
If Nz(Me!Contract_Neg_Number, "") = "" Then sMissingValues = sMissingValues + vbCrLf + "Contract_Neg_Number"
If Nz(Me!Validity_Period, "") = "" Then sMissingValues = sMissingValues + vbCrLf + "Validity_Period"
If sMissingValues <> "" Then
MsgBox "You have left the following mandatory fields empty:" & vbCrLf & sMissingValues
End If
End Sub

How to print text lines in a textbox before using Append.Text in windows form vb.net

I am trying to add the contents of my five text boxes in the form to a multi line text box named "TextBox1". However, everytime I change the content of my textboxes, instead of adding another line with the contents it replaces the pre-existing line. How do I make the next line print.
Dim Newline As String
Newline = System.Environment.NewLine
TextBox1.Text = "Plane Truss"
TextBox1.Text = TextBox1.Text & Newline & "JointCoordinates"
TextBox1.AppendText(Newline & Joint# & " " & coordinates1 & " " & bc1 & " " & jointloads1 & " " & settlements1 & " " & jointrotation1)
Is there a way I can convert the whole multiline text box into a .txt
file?
Sure...use the Lines() property of the TextBox and File.WriteAllLines():
System.IO.File.WriteAllLines("c:\some path\folder\file.txt", Result1.Lines)

Replacing 2x vbCrLf at once

I have a string in which I'm trying to replace all VbCr / VbLf with VbCrLf. This is in an attempt to scrape some HTML.
My code looks like this:
leHTML = leHTML.Replace(vbLf, vbCrLf)
leHTML = leHTML.Replace(vbCr, vbCrLf)
However in many cases I'm then left with 2x vbCrLf of which I only want 1.
leHTML = leHTML.Replace(vbCrLf & vbCrLf, vbCrLf)
The line above doesn't seem to be doing anything. How can I replace 2x vbCrLf with 1x vbCrLf? Is there a better way of going about "normalizing" Line Feeds and Carriage Returns?
You should not replace a correct vbCrLf in the first place. Instead replace only those characters where replacement is necessary. A handy tool for this task is a regular expression.
There are two cases that you want to get rid off:
vbCr with no following vbLf
the Regex for this is (vbCr)(?!vbLf)
vbLf with no preceeding vbCr
the Regex for this is (?<!vbCr)(vbLf)
Putting this together, we get the following regex:
Dim regex = New Regex("((" & vbCr & ")(?!" & vbLf & ")|(?<!" & vbCr & ")(" & vbLf & "))")
Throw this on your input and you're done:
leHTML = regex.Replace(leHTML, vbCrLf)
Here is a simple test program (vbCr and vbLf have been replaced by cr and lf respectively, so there is a visible output):
Dim str = "crlf cr cr lf crlf lf"
Dim regex = New Regex("((cr)(?!lf)|(?<!cr)(lf))")
str = regex.Replace(str, "crlf")
Console.WriteLine(str)
The result is:
crlf crlf crlf crlf crlf crlf
You're going to have to work a little harder at this. Instead of blindly replacing characters, you need to see what is there first, then determine what you are replacing. For example (this is NOT the complete code):
if leHTML.contains(vbcr) andalso leHTML.contains(vblf) then
leHTML = leHTML.Replace(vbCr & vbLf, vbCrLf)
elseif leHTML.contains(vbcr) then
leHTML = leHTML.Replace(vbCr, vbCrLf)
elseif leHTML.contains(vblf) then
leHTML = leHTML.Replace(vbLf, vbCrLf)
else
...
end
Probably this is a good pattern to use a Regex replace expression.
For example
Dim pattern = "(\r|\n)"
Dim search = "The" & vbCr & "Test string" & vbCr & _
"used as an" & vbLf & "Example" & vbCrLf & "."
Dim m = Regex.Replace(search, pattern, vbCrLf)
Console.WriteLine(m)
The first line prepare the pattern to search for using the C# syntax for vbCr=\r and vbLf=\n enclosing the two characters in an optional group (find a vbCr or a vbLf).
Then the replace method search one or the other char and replace it with the double vbCrLf character sequence.
But now we have a problem, the single vbCrLf present in the test string has been doubled, so you need another replace to remove the double sequence with just one vbCrLf
pattern = "\r\n\r\n"
m = Regex.Replace(search, pattern, vbCrLf)
Console.WriteLine(m)

split a string and output to a listbox in ms access 2007

if i have a textbox with contents like "the big brown fox jumped over the lazy dog",
how do i split it and put the contents in a listbox like this:
0,the
1,big
2,brown
3,fox
4,jumped
5,over
6,the
7,lazy
8,dog
PLz help, newbie
You could use the Split() function. Something like this:
Public Function SplitToListBox(ByVal strInput As String) As String
Dim strTemp() As String
Dim intCounter As Integer
Dim strRowsource As String
Const strQuote As String = """"
strTemp() = Split(strInput, " ")
For intCounter = 0 To UBound(strTemp())
If Len(strRowsource) = 0 Then
strRowsource = strQuote & Trim(CStr(intCounter)) & strQuote & "; " & strQuote & strTemp(intCounter) & strQuote
Else
strRowsource = strRowsource & "; " & strQuote & Trim(CStr(intCounter)) & strQuote & "; " & strQuote & strTemp(intCounter) & strQuote
End If
Next intCounter
SplitToListBox = strRowsource
End Function
Now, you'd then need a listbox defined with two columns, and you'd want to set the widths on those columns appropriately (0.5";1" works if you want to see both; 0";1" works if you want the first column to be hidden (though it will be the bound column if you don't change the default properties). You also need to set the RowSourceType property to "Value List".
One caveat:
There's a hard limit on the length of the Rowsource property when it's a Value List. I can't remember the exact number, but it's somewhere upward of 2000 characters. If you need more than that, then I'd suggest you convert the code that creates the list to a custom function. There are instructions on how to do this in the help for combo-/listboxes.