How can I get text to NOT overlap in Small Basic? - windows

I need to have a graphics window that displays a message over and over again as a user clicks a button. I have looked all over the internet for instructions on how to not make it overlap. This is most likely a quick fix but idk. Plz help here is my code. I am trying to make a clicker game but haulted as this issue happened.
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")
ElseIf eggs >= 1 Then
GraphicsWindow.BackgroundColor = "White"
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")
EndIf
EndSub

As far as I know, this exact effect isn't possible in Small Basic, because things drawn to the GraphicsWindow can't be edited or removed without clearing the entire window.
Instead, I would use a TextBox from Controls, which can be edited after they've been created. Because the TextBox can normally be edited by the user, I've also added code to prevent the content from being edited.
See my comments in the code for more about how this works.
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
' Create a text box to show the egg count
myTextBox = Controls.AddTextBox(0, 0)
' Ensure the user can't edit its contents by resetting the text if it changes
Controls.TextTyped = updateEggs
Sub updateEggs
' Change the text of myTextBox
Controls.SetTextBoxText(myTextBox, "You have " + eggs + " eggs")
EndSub
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
updateEggs()
ElseIf eggs >= 1 Then
GraphicsWindow.BackgroundColor = "White"
updateEggs()
EndIf
EndSub
This GIF demonstrates how the TextBox looks and works, as well as how the text cannot be changed:

All you have to do is use Shapes.AddText. This will create a text shape that can be modified with Shapes.SetText
Example:
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
Text = Shapes.AddText("You have 0 eggs")
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
Shapes.SetText(Text,"You have " + eggs + " eggs")
EndIf
EndSub

Related

Display Images from a File into Pictureboxes

I have a folder called
App.Path & "\Images"
Inside of it I have 5 Images and in my Form I have also 5 Pictureboxes. Now my question is, How can I display them all one PictureBox per Image at a time? heres is my code so far
Picture1.Picture = LoadPicture("Path")
Heres what I've done so far
Dim c As Control
Dim ImageLink As String
With vs1
For Each c In Form1
For i = 1 To .Rows - 1
If Len(ImageLink) > 0 Then ImageLink = ImageLink
Debug.Print c.Picture
Debug.Print .TextMatrix(i, .ColIndex("Image"))
MsgBox .TextMatrix(i, .ColIndex("Image"))
c.Picture = LoadPicture("C:\Users\paul\Desktop\Gondola Monitoring System\Image\" & .TextMatrix(i, .ColIndex("Image")))
Next
Next
End With
Form1.Show
I try to write the filename in flexgrid and call it in each control.
TYSM for help
Picture1.Picture = LoadPicture(App.Path & "\Images\file1.jpg")
Picture2.Picture = LoadPicture(App.Path & "\Images\file2.jpg")
Picture3.Picture = LoadPicture(App.Path & "\Images\file3.jpg")
Picture4.Picture = LoadPicture(App.Path & "\Images\file4.jpg")
Picture5.Picture = LoadPicture(App.Path & "\Images\file5.jpg")
If this doesn't provide you with what you need, please provide more details on your requirements.
EDIT
Your code isn't going to work. You are looping over all the controls, which will include any buttons, labels, etc, in addition to your picture controls, and for each control you are looping through all the rows of your grid. One better approach would be to define the picture controls as an array (starting index from 1 to match your grid for loop), then the for index is used so that the grid rows and picture indexes match. Something like this:
With vs1
For i = 1 To .Rows - 1
Picture1(i).Picture = LoadPicture("C:\Users\paul\Desktop\Gondola Monitoring System\Image\" & .TextMatrix(i, .ColIndex("Image")))
Next
End With

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)

how Imitate RCTRL + "f" pressing

This is not what I need:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys("^{f}")
It popups search form.
RCTRL + f - sets my window form to full screen, so,
How can I get imitation of RCTRL + f keys press?
In Form_load add the following two lines:
Me.BorderStyle = vbBSNone
Me.WindowState = wdWindowStateMaximize

how to dynamically give names to buttons using a listbox

Dim cont = 0
If ListBox1.Items.Count > 0 Then
For i =1 To ListBox1.Items.Count
Dim botao3 As New Button
botao3.Text = CStr(ListBox2.Items(cont)) 'table.Item(i).text &
botao3.BringToFront()
botao3.Top = top
botao3.Left = 40
botao3.Width = 300
Me.Controls.Add(botao3)
top = top + 30
cont = cont + 1
Next
End If
ps. my listbox has the sorted propriety set to true
this its my code but it will only give it the name of the last inserted value on the listbox .
how can i make this so that when ever i click the button it deletes the old set of buttons and add a new set of button the one i have just inserted.
and please give me a hand :$
You put 0 instead of the current loop value
botao3.Text = CStr(ListBox2.Items(0))
should be
botao3.Text = CStr(ListBox2.Items(i))
For the other part, I am not sure what you want to achieve but you can have Me.Controls.Clear() before your loop.
try that:
If ListBox1.Items.Count > 0 Then
For i =0 To ListBox1.Items.Count
Dim botao3 As New Button
botao3.Text = CStr(ListBox1.Items(i)) 'table.Item(i).text &
botao3.BringToFront()
botao3.Top = top
botao3.Left = 40
botao3.Width = 300
Me.Controls.Add(botao3)
top = top + 30
Next
End If
use this:
Dim btn As Button() = New Button(ListBox1.Items.Count - 1) {}
For i As Integer = 0 To ListBox1.Items.Count - 1
btn(i) = New Button()
btn(i).Text = ListBox1.Items(i).ToString()
If i > 0 Then
btn(i).Left = btn(i - 1).Right
End If
Me.Controls.Add(btn(i))
Next
result:

Resources