Reputation: 11
So, here's the code I want to be in string :
TEAM_SUPERADMIN = DarkRP.createJob("Superadmin on Duty", {
color = Color(0, 0, 0, 255),
model = {"models/player/group01/male_01.mdl"},
description = [[This is the Superadmin on Duty job!]],
weapons = {"weapon_fists", "unarrest_stick"},
command = "superadmin",
max = 5,
salary = 45,
admin = 0,
vote = false,
hasLicense = false,
})
My attempt to put this into a text box was this:
TextBox14.Text = "TEAM_SUPERADMIN = DarkRP.createJob("Superadmin on Duty", {
color = Color(0, 0, 0, 255),
model = {"models/player/group01/male_01.mdl"},
description = [[This is the Superadmin on Duty job!]],
weapons = {"weapon_fists", "unarrest_stick"},
command = "superadmin",
max = 5,
salary = 45,
admin = 0,
vote = false,
hasLicense = false,
})"
But it thought the string I was the text inside the first two quotes. Please help!
Upvotes: 1
Views: 102
Reputation: 4742
Every place you want quotes you'll need double quotes. ""Superadmin on Duty""
If you're going to have the string on multiple lines, you need to have line continuation. Close the string and then put a _ at the end of the line. Then start the next line with & "more stuff..."
So the first couple of lines would look like:
TextBox14.Text = "TEAM_SUPERADMIN = DarkRP.createJob(""Superadmin on Duty"", {" & VbCrLf _
& "color = Color(0, 0, 0, 255)," & VbCrLf _
There are several other ways to do this as well. You can use the += to just keep adding text to a variable or control:
TextBox14.Text = "TEAM_SUPERADMIN = DarkRP.createJob(""Superadmin on Duty"", {" & VbCrLf
TextBox14.Text += "color = Color(0, 0, 0, 255)," & VbCrLf
TextBox14.Text += "..."
Numerous ways you can concatenate a string in a variable, and then assign the control's text to the contents of the variable. See Create a string and append text to it.
Upvotes: 2
Reputation: 2089
I would hazard a guess that you may want to save more than one block of code.
And if you use any of the other approaches you will have HARD CODE by hand each code block.
Therefore it makes sense to develop a subroutine to do the donkey work for you!
Something along the lines of...
Function Stringify(ByVal Textdata As String) As String
'
Dim buf As String
Dim counta As Integer
'
buf = ""
For counta = 1 To Len(Textdata)
If Mid(Textdata, counta, 1) = Chr(34) Then
buf = buf & """ & chr(34) & """
Else
buf = buf & Mid(Textdata, counta, 1)
End If
Next
Stringify = Chr(34) & buf & Chr(34)
'
End Function
And you would call the function as....
MyConvertedCodeString = Stringify(txtTextData.text)
Upvotes: -1
Reputation: 6206
replace double quotes with double double quotes within the string and build the string with caraige returns:
TextBox14.Text = "TEAM_SUPERADMIN = DarkRP.createJob(""Superadmin on Duty"", {" _
& vbLf & "color = Color(0, 0, 0, 255)," _
& vbLf & "model = {""models/player/group01/male_01.mdl""}," _
& vbLf & "description = [[This is the Superadmin on Duty job!]]," _
& vbLf & "weapons = {""weapon_fists"", ""unarrest_stick""}," _
& vbLf & "command = ""superadmin""," _
& vbLf & "max = 5," _
& vbLf & "salary = 45," _
& vbLf & "admin = 0," _
& vbLf & "vote = false," _
& vbLf & "hasLicense = false," _
& vbLf & "})"
Note the space after the underscore, I just tested with this and it works:
MsgBox("TEAM_SUPERADMIN = DarkRP.createJob(""Superadmin on Duty"", {" _
& vbLf & "color = Color(0, 0, 0, 255)," _
& vbLf & "model = {""models/player/group01/male_01.mdl""}," _
& vbLf & "description = [[This is the Superadmin on Duty job!]]," _
& vbLf & "weapons = {""weapon_fists"", ""unarrest_stick""}," _
& vbLf & "command = ""superadmin""," _
& vbLf & "max = 5," _
& vbLf & "salary = 45," _
& vbLf & "admin = 0," _
& vbLf & "vote = false," _
& vbLf & "hasLicense = false," _
& vbLf & "})")
You can see the difference on the SO forum as it formats text as red (Look at your code compared to mine)
Upvotes: 2