Line Break for Array in VB 6.0 - vb6

I want to ask on how do to break the lines of arrays. I was making a questionnaire, when I encountered this. What I just want to do is literally just break the lines of the codes so that it won't be very long
I don't know where to start, so here is my first code:
Public Sub showQuestion()
Dim letter
Dim X As Integer
Dim Y As Integer
Randomize
question = Array("A programming language originally developed by James Gosling at Sun Microsystems", "A programming language from Microsoft", "Determines when the user wants to do something such as exit the application or begin printing", "Property information", "GUI information and private code")
answer = Array("Java", "Visual_Basic", "Command_Button", "Property_page", "Form")
question = Array("Specifies the background color of the control", "Generally, specifies whether or not a control has a border", "Determines whether or not the control can respond to user-generated events", "For controls displaying text, specifies the font (name, style, size, etc.) to be applied to the displayed text")
answer = Array("BackColor", "BorderStyle", "Enabled", "Font")
question = Array("Specifies the color of text or graphics to be displayed in the control", "Specifies the height of the control in pixels", "The string value used to refer to the control in code", "Specifies the graphic to be displayed in the control")
answer = Array("ForeColor", "Height", "Name", "Image")
qno = Int(Rnd * (UBound(question) + 1))
ReDim ans(Len(answer(qno)), 2)
lblquestion.Caption = question(qno)
For X = 0 To Len(answer(qno)) - 1
ans(X, 1) = Mid$(answer(qno), X + 1, 1)
Next X
For Y = 0 To Len(answer(qno)) - 1
If ans(Y, 1) = "_" Then
ans(Y, 2) = Chr$(32)
Else
ans(Y, 2) = "*"
End If
Next Y
loadHint
End Sub

Based on your clarification, you can break the line by using an underscore(_) something like this.
question = Array("A programming language originally developed by James Gosling at Sun Microsystems", _
"A programming language from Microsoft", _
"Determines when the user wants to do something such as exit the application or begin printing", _
"Property information", "GUI information and private code")
answer = Array("Java", "Visual_Basic", "Command_Button", _
"Property_page", "Form")

Related

Decompose lines of standard powerpoint shape

I would like to split a standard PowerPoint shape into separate lines so that I can have full control over how and when they appear when using animations. Thus, I would like to see that the shape on top (a standard PowerPoint shape) is decomposed in the one below (without the space betwen the lines.
I hope somebody has some creative ideas.
This may help get started. Look up the docs on the various properties/methods for more information.
Sub thing()
Dim oSh As Shape
Dim x As Long
Dim pointsArray()
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
Debug.Print .Nodes.Count
With .Nodes
For x = 1 To .Count
Debug.Print "X = " & .Item(x).Points(1, 1)
Debug.Print "Y = " & .Item(x).Points(1, 2)
Next
End With
End With
End Sub

2 different color text in one cell

We are putting together a new standard signature using vbs for Outlook.
Everything looks great but design would like the phone numbers to look like the attached image. The "O" for office # in Orange and then the number in blue, the "C" for cell # in Orange and then the number in blue.
I can get the entire cell to be one color, but I don't see how to do 2 colors.
The signature is in a table with the logo in one cell that has 5 rows merged and then the other side has 5 rows.
Here is some of my code:
strName = objUser.FullName
strTitle = objUser.Title
strPhone = objUser.telephoneNumber
strMobile = objUser.mobile
strOffice = "O "
strCell = "C "
objTable.Cell(3,2).Range.Font.Name = "Lato"
objTable.Cell(3,2).Range.Font.Size = "12"
objTable.Cell(3,2).Range.Text = strOffice & strPhone & " " & strCell & strMobile
Start recording a macro do it manually by editing the in the cell or the formula bar. Stop the macro and step into it to get all the colors. I stuck to the main colors on the bottom of the pallet. You'll may have to track ThemeColor, TintAndShade and ThemeFont depending on the colors you choose.
This should get you started
Public Sub AddLogo(r As Range)
Dim i As Integer
Dim ColorArray
ColorArray = Array(-16777024, -16776961, -16727809, -16711681, -11480942, -11489280, -1003520, -4165632, -10477568, -6279056)
r = "Excel Magic"
For i = 0 To UBound(ColorArray)
With r.Characters(Start:=(i + 1), Length:=1).Font
.Color = ColorArray(i)
End With
Next
End Sub
Usage:
AddLogo objTable.Cell(3,2)

How can I make a VBS Message Box appear in a random place?

In VBS script, I have created a simple message box application. It currently stays in front of all windows until the user responds and uses very simple coding
X=MsgBox("Test Text" ,1+4069, "Test Title")
But it always appears in the same place. Is there any way of making it appear in a random place on the screen? Please help!
There is one type of box which allows you to position it on the screen: InputBox
Title = "Hello"
DefaultValueText = "Hello Stackoverflow !"
message = "Type something here"
XPos = 0
YPos = 0
Text = InputBox(message,Title,DefaultValueText,XPos,YPos)
XPos = 3000
YPos = 800
Text = InputBox(message,Title,DefaultValueText,XPos,YPos)
#Hackoo was almost there,
I used his and here is what I made out of it.
dim r
randomize
r = int(rnd*500) + 1
r2 = int(rnd*1500) + 1
Title = "Hello"
DefaultValueText = "Hello!"
message = "Type something here!"
XPos = r
YPos = r2
Text = InputBox(message,Title,DefaultValueText,XPos,YPos)

Visual Basic 2013 Color to code

I wanna make color selector, when picked color write color code to text box. I created color dialog and text boxes, how make a rgb and hex codes from picked color?
I'm trying this code, but it have a problem:
TextBox1.Text = ColorDialog1.Color.R + ", " + ColorDialog1.Color.G + ", " + ColorDialog1.Color.B
Getting:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string ", " to type 'Double' is not valid.
Something like this will get you what you need...
Dim MyColor = Color.LightGreen
Dim R = MyColor.R
Dim G = MyColor.G
Dim B = MyColor.B
Dim HexString = String.Format("{0:X2}{1:X2}{2:X2}", R, G B)
Visual Basic is usually pretty accommodating when you try to combine numbers and text, automatically converting the number to a string to make the statement work. But the Color.R, G and B properties are a bit special, they are of type Byte. That type didn't exist in earlier versions of VB. They didn't add the automatic conversion.
Best thing to do here is to use the composite formatting feature supported by the String.Format() method:
With ColorDialog1.Color
Label1.Text = String.Format("{0}, {1}, {2}", .R, .G, .B)
End With
And for the hex version just change the formatting string:
Label1.Text = String.Format("#{0:x2}{1:x2}{2:x2}", .R, .G, .B)

"New Scope" Macro for Visual Studio

I'm trying to create a new macro that takes the currently selected text and puts curly braces around it (after making a newline), while, of course, indenting as needed.
So, for example, if the user selects the code x = 0; and runs the macro in the following code:
if (x != 0) x = 0;
It should turn into:
if (x != 0)
{
x = 0;
}
(Snippets don't help here, because this also needs to work for non-supported source code.)
Could someone help me figure out how to do the indentation and the newlines correctly? This is what I have:
Public Sub NewScope()
Dim textDoc As TextDocument = _
CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
textDoc.???
End Sub
but how do I figure out the current indentation and make a newline?
Sub BracketAndIndent()
Dim selection = CType(DTE.ActiveDocument.Selection, TextSelection)
' here's the text we want to insert
Dim text As String = selection.Text
' bracket the selection;
selection.Delete()
' remember where we start
Dim start As Integer = selection.ActivePoint.AbsoluteCharOffset
selection.NewLine()
selection.Text = "{"
selection.NewLine()
selection.Insert(text)
selection.NewLine()
selection.Text = "}"
' this is the position after the bracket
Dim endPos As Integer = selection.ActivePoint.AbsoluteCharOffset
' select the whole thing, including the brackets
selection.CharLeft(True, endPos - start)
' reformat the selection according to the language's rules
DTE.ExecuteCommand("Edit.FormatSelection")
End Sub
textDoc.Selection.Text = "\n{\n\t" + textDoc.Selection.Text + "\n}\n"
Of course the amount of \t before the { and } and Selection depend on the current indention.
Since there is a difference between selected Text and Document data, it's hard to find out where the cursor is within the document's data (at least in Outlook it is).
The only way I figured out how to do this in Outlook is to actually move the selection backwards until I got text that I needed, but that resulted in undesirable effects.
Try taking the selection start, and using that position in the document text, looking at that line and getting the amount of tabs.
I would think there wouldn't be formatting characters in VStudio.

Resources