In my Application i need to display some short notes in label.
So i tried like this
lable1.Text="HELP : " & vbNewLine & vbNewLine & "1. You can Remove or
Replace existing Main Icons" & vbNewLine & vbNewLine _
& "2. If you want to remove any buttons, Right click on Icon and
select UNPIN or select the " _
& " Icon and press delete button from key borad" & vbNewLine &
vbNewLine & "3. Drag the needed button from top menu and drop it on
empty space in Icons." & vbNewLine & vbNewLine & "4. If Reports
having sub reports, You can drag and drop the sub reports only."
If the points in came to second line its start from 2 but i need all letter start same level like this
1 . aaaa
2. bbbbb
vvvvv.
and Help must have underline. How to do it. Can say which control good for this can you give some example also.
am using VB.Net 2008
I dont think you can set tabs in a label, so you might need to manually space the text using a monospaced font. But in a richtextbox, you can do this.
RichTextBox1.Text = "HELP : " & vbNewLine & vbNewLine &
"1." & vbTab & "You can Remove or Replace existing Main Icons" & vbNewLine & vbNewLine &
"2." & vbTab & "If you want to remove any buttons, Right click on Icon and" & vbNewLine _
& vbTab & "select UNPIN or select the Icon and press delete button from keyboard" & vbNewLine & vbNewLine &
"3." & vbTab & "Drag the needed button from top menu and drop it on" & vbNewLine _
& vbTab & "empty space in Icons." & vbNewLine & vbNewLine &
"4." & vbTab & "If Reports having sub reports, You can drag and drop the sub reports only."
RichTextBox1.SelectAll()
RichTextBox1.SelectionTabs = {20}
RichTextBox1.DeselectAll
Related
Is there a way to Aline to tab, non-fixed-pitch font text in a textbox.
TextBox1.AppendText("Sample text line" & vbTab & vbTab & vbTab & "(100)" & vbNewLine)
TextBox1.AppendText("Sample text line Sample text line" & vbTab & vbTab & vbTab & "(150)" & vbNewLine)
TextBox1.AppendText("Sample text line" & vbTab & vbTab & vbTab & "(200)" & vbNewLine)
I want to aline to two columns those texts using tab char. Can not hardcode vbTab for each line because of texts are dynamically changing.
I have a workbook with an userform that captures user input into string and single variables and I want to display a text consisting those variables into a text box on the same userform using new line and tab.
Example:
Dim dog as String 'rex
Dim years as Single '5
Dim owner As String 'Joe
Dim address as String '123 Sample Street
Dim value as Single '300.00
I would like to have a textbox on my form, that would display:
The dog's name is rex. He is 5 years old.
Owner: Joe
Address: 123 Sample Street
Treatment value: 300.00
I used
textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine & "Owner: " & owner & vbNewLine & "Address: " & address & vbNewLine & vbNewLine & "Treatment value: " & value
But after some time i will not be able to add another character to this line and I have plenty more variables mixed with text to come.
Can you suggest how this can be done?
Update: Resolved
Many thanks for your help.
Try
textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine
textbox.value = textbox.value & "Owner: " & owner & vbNewLine
textbox.value = textbox.value & "Treatment value: " & value & vbNewLine
Continue with other fields!
Try like this:
textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine & _
"Owner: " & owner & vbNewLine & _
"Address: " & address & vbNewLine & vbNewLine _
& "Treatment value: " & value
The " _" signs help you break the code into more lines. Note, that we have 2 signs - space and underscore there.
A small info - it is possibly good to consider passing the text as a .Text and not as .Value. Here is something good to read - Distinction between using .text and .value in VBA Access
The following code looks for certain text strings in a column and gives a msg box whenever something matches. The code looks for more than one text string, so if I have "X" AND "y" in one column and the code looks for both text strings, then two msg boxes will appear. I only want the first msg box to show and hide the rest. Is there a way to do this?
In other words, code looks for multiple text strings, pops up msg boxes if text strings match. More than one text string will definitely match, but I want only the first box to appear, and hide the rest.
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icounter As Long
Dim icounter1 As Long
Dim lastrow As Long
Dim MSG As String, ans As Variant
For icounter = 2 To 31
If Cells(icounter, 2) = "Job Code Name" Then
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. PS Group" & vbNewLine & "2. Level" & vbNewLine & "3. Box Level" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
ElseIf Cells(icounter, 2) = "Personnel Area" Then
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Personnel Subarea" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
ElseIf Cells(icounter, 2) = "Line of Sight" Then
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. 1 Up Line of Sight" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
ElseIf Cells(icounter, 2) = "Title of Position" Then
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Job Code Name" & vbNewLine & "2. PS Group" & vbNewLine & "3. PS Level" & vbNewLine & "4. Box Level" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
ElseIf Cells(icounter, 2) = "Company Code Name" Then
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Cost Center" & vbNewLine & "2. Line of Sight" & vbNewLine & "3. 1 Up Line of Sight" & vbNewLine & "4. Personnel Area" & vbNewLine & "5. Location" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
ElseIf Cells(icounter, 2) = "Function" Then
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Sub Function" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Else
End If
Next icounter
End Sub
If I understand your question, you could use Select Case instead of all the If...ElseIf stuff. Just reading the comments. Apparently you want to exit the For loop as well so add Exit For.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icounter As Long
Dim icounter1 As Long
Dim lastrow As Long
Dim MSG As String, ans As Variant
For icounter = 2 To 31
Select Case Cells(icounter, 2)
Case "Job Code Name"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. PS Group" & vbNewLine & "2. Level" & vbNewLine & "3. Box Level" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Personnel Area"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Personnel Subarea" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Line of Sight"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. 1 Up Line of Sight" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Title of Position"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Job Code Name" & vbNewLine & "2. PS Group" & vbNewLine & "3. PS Level" & vbNewLine & "4. Box Level" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Company Code Name"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Cost Center" & vbNewLine & "2. Line of Sight" & vbNewLine & "3. 1 Up Line of Sight" & vbNewLine & "4. Personnel Area" & vbNewLine & "5. Location" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Function"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Sub Function" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
End Select
Next icounter
End Sub
I would recommend you another refactoring in your code. Since you are using a Worksheet event, every time you change a cell content it will fire that event, so I believe you add Application.EnableEvents = False before your For loop and Application.EnableEvents = True after it.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icounter As Long
Dim icounter1 As Long
Dim lastrow As Long
Dim MSG As String, ans As Variant
Application.EnableEvents = False
For icounter = 2 To 31
Select Case Cells(icounter, 2)
Case "Job Code Name"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. PS Group" & vbNewLine & "2. Level" & vbNewLine & "3. Box Level" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Personnel Area"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Personnel Subarea" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Line of Sight"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. 1 Up Line of Sight" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Title of Position"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Job Code Name" & vbNewLine & "2. PS Group" & vbNewLine & "3. PS Level" & vbNewLine & "4. Box Level" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Company Code Name"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Cost Center" & vbNewLine & "2. Line of Sight" & vbNewLine & "3. 1 Up Line of Sight" & vbNewLine & "4. Personnel Area" & vbNewLine & "5. Location" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
Case "Function"
MsgBox ("Please note you may need to add in additional attributes under this field" & vbNewLine & vbNewLine & "1. Sub Function" & vbNewLine & vbNewLine & "Please add in these additional fields as needed")
Exit For
End Select
Next icounter
Application.EnableEvents = False
End Sub
I used Tim's answer but it fired whenever I made an edit to any cell in the sheet. To avoid this, I added this line of code before Select Case Cells(icounter, 2):
If Not Intersect(Target, Cells(icounter, 2)) Is Nothing Then
This edit has made the msg box pop up only when cells change to the string text I inputted, i.e. company code name
So, I'm currently working on a program that should create Lua-Scripts for the Unitale-Engine. I added a "New Project" button which should create a new project file when you click it. I want this file to contain the default project-file-text. So i did this:
Dim File1 As String = "monster{" & vbNewLine & "COMMENTS=Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow." & vbNewLine & "COMMANDS=Compliment;Threaten" & vbNewLine & "DEFAULT_SPRITE=None" & vbNewLine & "NAME=Froggit" & vbNewLine & "HP=10" & vbNewLine & "ATK=1" & vbNewLine = "DEF=0" & vbNewLine & "CHECK_MESSAGE=Life is difficult for this enemy." & vbNewLine & "HandleAttack=" & vbNewLine & "OnDeath=" & vbNewLine & "HandleCustomCommand=" & vbNewLine & "}"
Dim File2 As String = vbNewLine & "encounter{" & vbNewLine & "DEFAULT_MUSIC=Fight" & vbNewLine & "ENCOUNTER_TEXT=Froggit hops close." & vbNewLine & "NEXTWAVES=1" & vbNewLine & "WAVETIMER=6" & vbNewLine & "ARENASIZE=155;130" & vbNewLine & "ENEMIES=Froggit" & vbNewLine & "ENEMYPOSITIONS=0;0" & "EncounterStarting=" & vbNewLine & "EnemyDialogueStarting=" & vbNewLine & "EnemyDialogueEnding=" & vbNewLine & "DefenseEnding=" & vbNewLine & "HandleItem=" & vbNewLine & "HandleSpare=" & vbNewLine & "EnteringState=" & vbNewLine & "Update=" & vbNewLine & "}"
Dim File3 As String = vbNewLine & "waves{" & vbNewLine & "1=Do Nothing" & vbNewLine & "}" & vbNewLine & "end"
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\UnitaleMaker\Projects\" & PJNBox.Text & ".umproj", File1 & File2 & File3, False)
Yes, that is a lot of text. The problem is, that File1 always sets its value to "False" when it is declared. I thought that is because the string is too long, so I split it to 3 parts, but it doesn't work.
Any help would be apprechiated!
~ Mika // OneByte_
Starting with VB 14 (Visual Studio 2015), you can span String literals across multiple lines. VB 14 also adds String interpolation, which makes for much cleaner code. You could write your code like the following which would have kept you from having made your mistake of & vbNewLine = "DEF=0" &and would overall make the code easier to read.
I am also assuming you forgot a newline in "ENEMYPOSITIONS=0;0" & "EncounterStarting=" and I have indented the parts between the {}. I combined File1, File2, and File3 back into a single string since you stated you broke them up in the question, I assumed you'd rather have it all in one string.
Dim File1 As String = "monster{
COMMENTS = Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow.
COMMANDS=Compliment;Threaten
DEFAULT_SPRITE=None
NAME=Froggit
HP=10
ATK=1
DEF=0
CHECK_MESSAGE=Life Is difficult For this enemy.
HandleAttack=
OnDeath=
HandleCustomCommand=
}
encounter{
DEFAULT_MUSIC = Fight
ENCOUNTER_TEXT =Froggit hops close.
NEXTWAVES=1
WAVETIMER=6
ARENASIZE=155;130
ENEMIES=Froggit
ENEMYPOSITIONS=0;0
EncounterStarting=
EnemyDialogueStarting=
EnemyDialogueEnding=
DefenseEnding=
HandleItem=
HandleSpare=
EnteringState=
Update=
}
waves{
1 =Do Nothing
}
End"
My.Computer.FileSystem.WriteAllText($"{My.Computer.FileSystem.SpecialDirectories.MyDocuments}\UnitaleMaker\Projects\{PJNBox.Text}.umproj", File1, False)
Please learn to use string.format.
Also I changed & to new line in file2:
"ENEMYPOSITIONS=0;0" & "EncounterStarting="
I just assumed you forgot to add new line there.
Alss Environment.NewLine is the best option for new lines as it is universal.
Dim File1 As String = String.Format("monster{{{0}COMMENTS=Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow.{0}COMMANDS=Compliment;Threaten{0}DEFAULT_SPRITE=None{0}NAME=Froggit{0}HP=10{0}ATK=1{0}DEF=0{0}CHECK_MESSAGE=Life is difficult for this enemy.{0}HandleAttack={0}OnDeath={0}HandleCustomCommand={0}}}", Environment.NewLine)
Dim File2 As String = String.Format("{0}encounter{{{0}DEFAULT_MUSIC=Fight{0}ENCOUNTER_TEXT=Froggit hops close.{0}NEXTWAVES=1{0}WAVETIMER=6{0}ARENASIZE=155;130{0}ENEMIES=Froggit{0}ENEMYPOSITIONS=0;0{0}EncounterStarting={0}EnemyDialogueStarting={0}EnemyDialogueEnding={0}DefenseEnding={0}HandleItem={0}HandleSpare={0}EnteringState={0}Update={0}}}", Environment.NewLine)
Dim File3 As String = String.Format("{0}waves{{{0}1=Do Nothing{0}}}{0}end", Environment.NewLine)
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\UnitaleMaker\Projects\" & PJNBox.Text & ".umproj", File1 & File2 & File3, False)
I've been trying to adapt the method shown here: http://support.microsoft.com/kb/246299 so that I can create a command button in word which will save the document and remove itself when clicked. I've been unable to figure out how to change the position of the button from the default of the top left of the first page however. Ideally I'd like the button to be generated at the end of the document and be centre aligned, or otherwise placed at the cursor position.
Any advice would be very much appreciated :)
Thank You.
My VB.NET project code so far:
Dim shp As Word.InlineShape
shp = wrdDoc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
shp.OLEFormat.Object.Caption = "Save To Disk"
shp.Width = "100"
'Add a procedure for the click event of the inlineshape
Dim sCode As String
sCode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & vbCrLf & _
"ActiveDocument.SaveAs(""" & sOutFile & """)" & vbCrLf & _
"On Error GoTo NoSave" & vbCrLf & _
"MsgBox ""Document Saved Successfully""" & vbCrLf & _
"Dim o As Object" & vbCrLf & _
"For Each o In ActiveDocument.InlineShapes" & vbCrLf & _
"If o.OLEFormat.Object.Name = ""CommandButton1"" Then" & vbCrLf & _
"o.Delete" & vbCrLf & _
"End If" & vbCrLf & _
"Next" & vbCrLf & _
"Exit Sub" & vbCrLf & _
"NoSave:" & vbCrLf & _
"MsgBox ""Document Failed To Save""" & vbCrLf & _
"End Sub"
wrdDoc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString(sCode)
wrdApp.Visible = True
As long as everything else is working just set the shp.left = 250 and shp.top = 1200
etc etc.
Just like in VB when you place a button. For more details on the exact calls you should reference this page: http://msdn.microsoft.com/en-us/library/office/hh965406%28v=office.14%29.aspx
But say to center a button you can set left to be the (doc.width - shape.width)
But word buttons allow for much more complex styling and setup.