how Imitate RCTRL + "f" pressing - vbscript

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

Related

I'm trying to accept a backspace input as a character

I'm writing a program in visual basic 2015 to add users to the school server. I have text box's, that aren't editable, to display input from other text boxes. Sounds more complicated than it is, but the text boxes simply show your entries, so a lot will be completed without having to double up on entries. As the input changes on an input textbox, it updates to the display. However, I cannot detect a backspace input to update the displayed content. Is there a way to do this?
Here's a sample of the code.
Private Sub dp_TextChanged(sender As Object, e As EventArgs) Handles dp.TextChanged
If dp.Text = "" Then GoTo line1
i = Asc(dp.Text)
If i = 8 Then
domainp.Text = domainp.Text.Remove(domainp.Text.Length - 1)
End If
If dp.Text = "" Or dp.Text = " " Or dp.Text = "." Then GoTo line1
domainp.Text = domainp.Text & dp.Text
domain_prefix = domainp.Text
dp.Text = ""
i = 0
line1:
End Sub
I haven't programmed for years and have forgotten a LOT of things. I would appreciate any help you could give me.
I am using visual studio 2015
Use the KeyDown event. This will capture any type, backspace, or arrow key movement.

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

Excel UserForm button click slow response time when clicked fast

I have a VBA UserForm in Excel, with very simple code. It displays a collection (a dictionary, actually) of objects, one at a time, with buttons for "first, previous, next, and last". Everything works great, but if I were to continually click the next button to go through the items, I have to click it slowly (roughly once a second). If I click any faster, the click is ignored. For example, if I click four times over two seconds, it will only 'register' the first and third click and advance twice, instead of four times.
Below is example code for the 'next' button (and the other applicable pieces of code in the userform module):
Private dQIDs As Dictionary
Public Sub TransferQIDs(ByVal dIncomingQIDs As Dictionary)
Set dQIDs = dIncomingQIDs
End Sub
Private Sub bNext_Click()
Call LoadQID(CLng(lIndex.Caption) + 1)
End Sub
Private Sub LoadQID(lQID As Long)
Dim QID As cQID
Set QID = dQIDs(lQID)
lIndex.Caption = lQID
lItems.Caption = "Viewing new QID " & lQID & " of " & dQIDs.Count
Me.tQID = QID.lQID
Me.tTitle = QID.sTitle
Me.tVID = QID.sVendorID
Me.bOS = QID.bOSPatch
Me.bApp = Not QID.bOSPatch
Me.bPrev.Enabled = Not (lQID = 1)
Me.bFirst.Enabled = Not (lQID = 1)
Me.bNext.Enabled = Not (lQID = dQIDs.Count)
Me.bLast.Enabled = Not (lQID = dQIDs.Count)
End Sub
Any ideas?
Personally I would just disable to button while content is loaded.
Private Sub bNext_Click()
Dim b1 As Button
Set b1 = ActiveSheet.Buttons("LoadQID")
REM or Me.LoadQID
b1.Font.ColorIndex = 15
b1.Enabled = False
Application.Cursor = xlWait
Call LoadQID(CLng(lIndex.Caption) + 1)
b1.Enabled = True
b1.Font.ColorIndex = 1
Application.Cursor = xlDefault
End Sub
Reason why this happens is that accessing a single object takes quite a bit of time in Excel. This way if you can click it will be registered.
Alternatively you can toggle UI update with:
Application.ScreenUpdating = False
Application.ScreenUpdating = True
windows is checking for a doubleclick. so if you click fast it registers a doubleclick.
2 options. increase you doubleclick speed in the windows mouse settings
or make a doubleclick event

Event Handlers for Dynamic Table Layout Panel in Visual Basic

I am making a risk-type game for school that dynamically creates a 4x4 grid of buttons inside a table layout panel in visual basic. I have successfully created the panel and buttons with names that correspond to the row and column of the button. There are also two parallel arrays - one for button owner and the other for button number - that correspond to the owner of the button and the number of "armies" in the button. My issue is that when the user clicks a certain button, I need to reference the button name/value to know how many "armies" the button has to control the "attack" portion of the player's turn.
The following code creates the table layout panel and the buttons with names.
'Create table Dynamically
Dim ColCount As Integer = 4
Dim RowCount As Integer = 4
Dim f As New System.Drawing.Font("Arial", 15)
riskTable.AutoScroll = True
riskTable.Dock = DockStyle.Fill
riskTable.ColumnCount = ColCount
riskTable.RowCount = RowCount
For rowNo As Integer = 0 To riskTable.RowCount - 1
For columnNo As Integer = 0 To riskTable.ColumnCount - 1
Dim buttonname As String
buttonname = "B" & rowNo & columnNo
Dim button As Control = New Button
button.Size = New Size(179, 100)
button.Name = buttonname
button.Text = "1"
button.ForeColor = Color.White
button.Font = f
AddHandler button.Click, AddressOf buttonname_Click
riskTable.Controls.Add(button, columnNo, rowNo)
Next
Next
Me.Controls.Add(riskTable)
This is the dynamic event handler that I created. I tried using 'Me.Click' to get the name of the button, but it only returns the name of the form. I need to have code in here that references the name of the currently clicked button to then in turn reference the box owner and box number arrays.
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
MessageBox.Show(Me.Name)
End Sub
Any help would be greatly appreciated! I think that once I get this working, the rest of the game will be pretty simple to figure out.
Thanks!
Put the name in 'button.Tag' instead/also:
button.Tag = buttonname
Then it is easy to get the name with:
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
Dim result As String = CType(CType(sender, System.Windows.Forms.Button).Tag, String)
End Sub
(Check the System.Windows.Forms.Button though, might need some tweak to match your buttons inside the table. riskTable.Controls.button ?)

How do I mimic pressing the "down" arrow in vb6?

I made a form and created a command button control. I would like to make it so that when the user presses the command button it sends a keystroke to a listbox of my choice.
Specifically, I want the command button to send a "down" arrow keystroke to a listbox (which will have focus) so that it goes from the current item to the next item.
How do I do this?
Let's say the name of my listbox is "lstFruits". I gave it focus, then tried SendKey.
Form.lstFruits.SetFocus.
SendKeys.Send ("{DOWN}")
Got the error "Argument not optional".
There is no need to emulate a keystroke, you can control the listbox in code;
lstFruits.SetFocus
if ((lstFruits.listindex + 1) < lstFruits.listcount) then
lstFruits.listindex = lstFruits.listindex+ 1
endif
Edit
Dim strName As String
strName = "lstFruits"
Dim lst As VB.ListBox: Set lst = TheForm.Controls(strName)
lst.SetFocus
If ((lst.ListIndex + 1) < lst.ListCount) Then
lst.ListIndex = lst.ListIndex + 1
End If

Resources