How to use arrow keys on Menu shortcuts in vb 6 - vb6

Using vb6's menu editor wizard I am able to create a menu for my window easily and with shortcut keys like CTRL + A to Z keys, SHIFT + F1-F12 keys, SHIFT + CTRL + F1 -F12 keys. However I am not able use other keys e.g Arrow leys like Up, Down, Left, Right, Page Down or Page Up.
I have observed the auto generate code on my frmMenu.frm file as below:
Begin VB.Form frmMenu
Caption = "Form1"
ClientHeight = 3015
ClientLeft = 225
ClientTop = 870
ClientWidth = 4560
LinkTopic = "Form1"
ScaleHeight = 3015
ScaleWidth = 4560
StartUpPosition = 3 'Windows Default
Begin VB.Menu mnuProjection
Caption = "&Projection"
Begin VB.Menu mnuArrowRight
Caption = "Arrow &Right"
End
Begin VB.Menu mnuArrowLeft
Caption = "Arrow &Left"
End
Begin VB.Menu mnuArrowUp
Caption = "Arrow &Up"
End
Begin VB.Menu mnuArrowDown
Caption = "Arrow &Down"
End
Begin VB.Menu mnuExit
Caption = "E&xit"
Shortcut = ^Q
End
End
End
Attribute VB_Name = "frmMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub mnuExit_Click()
Unload Me
End Sub
Any help would be appreciated like the code for such keys because they are lacking in the menu editor wizard

Related

VB6 Initialize event called AFTER Terminate event for user controls

I have created a simple form in VB6, and added a simple, blank user control. The only code are Debug.Print statements in all major events.
For some reason, when the form is closed, the order of events in the User Control are:
Terminate
Initialize
Read Properties
Resize
Why is this happening? Why are Initialize, ReadProperties and Resize called after Terminate? I could not find any evidence of this in Microsoft documentation.
EDIT:
Here is the code.
User control:
VERSION 5.00
Begin VB.UserControl UserControl1
ClientHeight = 3600
ClientLeft = 0
ClientTop = 0
ClientWidth = 4800
ScaleHeight = 3600
ScaleWidth = 4800
End
Attribute VB_Name = "UserControl1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Sub UserControl_Initialize()
Debug.Print "Initialize"
End Sub
Private Sub UserControl_InitProperties()
Debug.Print "InitProperties"
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Debug.Print "ReadProperties"
End Sub
Private Sub UserControl_Resize()
Debug.Print "Resize"
End Sub
Private Sub UserControl_Show()
Debug.Print "Show"
End Sub
Private Sub UserControl_Terminate()
Debug.Print "Terminate"
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Debug.Print "WriteProperties"
End Sub
Form:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3030
ClientLeft = 120
ClientTop = 450
ClientWidth = 4560
LinkTopic = "Form1"
ScaleHeight = 3030
ScaleWidth = 4560
StartUpPosition = 3 'Windows Default
Begin Project1.UserControl1 UserControl1
Height = 2535
Left = 240
TabIndex = 0
Top = 240
Width = 4095
_extentx = 7223
_extenty = 4471
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Debug.Print means your running this in debug mode in the IDE.
When debugging you would see a Terminate when the form unloads, you then see the reinitialisation of the User Control as its re-loaded in the Form in the Form Designer for editing.
This won't happen from a compiled EXE, you can replace Debug.Print with MsgBox to verify this.

Please modify PPT Macro

I have below macro.
Could you please modify it in such ways that it will show slide number on the top and also extract notes page.
I tried all ways but couldn't get answer-:
Sub WriteToWord()
Dim aSlide As Slide, MyDoc As New Word.Document, MyRange As Word.Range
Dim aTable As Table, aShape As Shape, TablesCount As Integer, ShapesCount As Integer
Dim i As Word.Paragraph
On Error Resume Next
With MyDoc
.Application.Visible = False
.Application.ScreenUpdating = False
For Each aSlide In ActivePresentation.Slides
For Each aShape In aSlide.Shapes
Set MyRange = .Range(.Content.End - 1, .Content.End - 1)
Select Case aShape.Type
Case msoAutoShape, msoPlaceholder, msoTextBox
If aShape.TextFrame.HasText Then
aShape.TextFrame.TextRange.Copy
MyRange.Paste
With MyRange
.ParagraphFormat.Alignment = wdAlignParagraphLeft
For Each i In MyRange.Paragraphs
If i.Range.Font.Size >= 16 Then
i.Range.Font.Size = 14
Else
i.Range.Font.Size = 12
End If
Next
End With
End If
Case msoPicture
aShape.Copy
MyRange.PasteSpecial DataType:=wdPasteMetafilePicture
ShapesCount = .Shapes.Count
With .Shapes(ShapesCount)
.LockAspectRatio = msoFalse
.Width = Word.CentimetersToPoints(14)
.Height = Word.CentimetersToPoints(6)
.Left = wdShapeCenter
.ConvertToInlineShape
End With
.Content.InsertAfter Chr(13)
Case msoEmbeddedOLEObject, msoLinkedOLEObject, msoLinkedPicture, msoOLEControlObject
aShape.Copy
MyRange.PasteSpecial DataType:=wdPasteOLEObject
ShapesCount = .Shapes.Count
With .Shapes(ShapesCount)
.LockAspectRatio = msoFalse
.Width = Word.CentimetersToPoints(14)
.Height = Word.CentimetersToPoints(6)
.Left = wdShapeCenter
.ConvertToInlineShape
End With
.Content.InsertAfter Chr(13)
Case msoTable
aShape.Copy
MyRange.Paste
TablesCount = .Tables.Count
With .Tables(TablesCount)
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 100
.Range.Font.Size = 11
End With
.Content.InsertAfter Chr(13)
End Select
Next
If aSlide.SlideIndex < ActivePresentation.Slides.Count Then .Content.InsertAfter Chr(12)
.UndoClear ' Clear used memory
Next
' Change white font to black color
With .Content.Find
.ClearFormatting
.Format = True
.Font.Color = wdColorWhite
.Replacement.Font.Color = wdColorAutomatic
.Execute Replace:=wdReplaceAll
End With
MsgBox "PPT Converted to WORD completed, Please check and save document", vbInformation + vbOKOnly, "ExcelHome/ShouRou"
.Application.Visible = True
.Application.ScreenUpdating = True
End With
End Sub
Sub Auto_Open() ' Add PPTtoWord to Tool Bar when Powerpoint start
Dim MyControl As CommandBarControl
On Error Resume Next
Application.CommandBars("Standard").Controls("PPTtoWord").Delete
Set MyControl = Application.CommandBars("Standard").Controls.Add(Before:=1)
With MyControl
.Caption = "PPTtoWord"
.FaceId = 567 ' Word Icon
.Enabled = True
.Visible = True
.Width = 100
.OnAction = "WriteToWord"
.Style = msoButtonIconAndCaption
End With
End Sub
Sub Auto_Close() ' Delete PPTtoWord from Tool Bar when Powerpoint close
On Error Resume Next
Application.CommandBars("Standard").Controls("PPTtoWord").Delete
End Sub
You are running this from Word and automating PowerPoint using early binding, you need to fully qualify any PowerPoint reference.
Have you added a reference to PowerPoint library.
Change to aShape As PowerPoint.Shape
Grab the reference to the running instance of PowerPoint. PowerPoint is single instance multi-use so you can use this.
Dim PPT as PowerPoint.Application
Set PPT = CreateObject("PowerPoint.Application")
Fully qualify all references to ActivePresentation with PPT.ActivePresentation
Your macro should run then and generate something so that you can continue debugging.

Flex grid non editable column

I don't want to edit some of the column in flex gird.
Flex Grid
column1, column2, .... column35
i want to edit from column1... column10 only, remaining columns i don't want to edit or type.
How to do in vb6.
I believe the MS Flex Grid was designed for displaying data and not editing. If you need to edit cell data you can accomplish it using the Flex Grid using an approach of superimposing a textbox at runtime to capture user data entry and set the "Text" property of the cell in code. Otherwise you can choose to use a different control.
Here are some examples of the aforementioned approach:
http://support.microsoft.com/kb/241355
http://www.vb-helper.com/howto_edit_flexgrid_control.html
I've made a special user control in VB6 to an editable grid. If you want I can send you a copy.
The code I use to enable to edit a cell is the follow:
Private Sub fg_KeyDown(KeyCode As Integer, Shift As Integer)
Dim Cancel As Boolean
Dim Idc As Long
Dim x
If KeyCode = vbKeyEscape And Shift = 0 Then
If Not fgLocked Then
If fgRowChanged Then
RaiseEvent BeforeRestoreBuffer
For Idc = 1 To UBound(fgBuffer)
x = fgBuffer(Idc)
fgValues(Idc, fg.Row) = x
If fgColFormat(Idc) = "*" And fgBuffer(Idc) <> "" Then
fg.TextMatrix(fg.Row, Idc) = "*******"
ElseIf fgColFormat(Idc) = "RTF" Then
fg.TextMatrix(fg.Row, Idc) = Format(fgBuffer(Idc), "")
Else
fg.TextMatrix(fg.Row, Idc) = Format(fgBuffer(Idc), fgColFormat(Idc))
End If
Next
fgRowChanged = False
RaiseEvent RestoreBuffer
End If
End If
ElseIf KeyCode = vbKeyReturn And Shift = 0 Then
NextCell
ElseIf KeyCode = vbKeyF2 And Shift = 0 Then
If Not fgLocked Then
If fgColFormat(fg.Col) = "RTF" Then
CellEditBig fgValues(fg.Col, fg.Row)
Else
CellEdit fgValues(fg.Col, fg.Row)
End If
End If
ElseIf KeyCode = vbKeyF2 And Shift = vbShiftMask Then
If Not fgLocked Then
CellEditBig fgValues(fg.Col, fg.Row)
End If
ElseIf KeyCode = vbKeyDelete And Shift = 0 Then
If Not fgLocked Then
RaiseEvent BeforeDelete(Cancel)
If Not Cancel Then
If fg.Rows = fg.FixedRows + 1 Then
fg.AddItem ""
If fgRowNumber Then fg.TextMatrix(fg.Rows - 1, 0) = fg.Rows - 1
fgValues_AddItem ""
End If
fg.RemoveItem fg.Row
If fgRowNumber Then Renumera
fgValues_RemoveItem fg.Row
LoadBuffer fg.Row
RaiseEvent AfterDelete
End If
End If
ElseIf KeyCode = vbKeyInsert And Shift = 0 Then
If Not fgLocked Then
RaiseEvent BeforeInsert(Cancel)
If Not Cancel Then
fg.AddItem "", fg.Row
If fgRowNumber Then Renumera
fgValues_AddItem "", fg.Row
RaiseEvent AfterInsert
End If
End If
Else
RaiseEvent KeyDown(KeyCode, Shift)
End If
End Sub

How to focus the next cell while clicking tab key and cell coloring

I am new to vb
Flexgrid
Header 01 .... 31
Values .........
I am entering the values at run time in flexgrid cell, if i click tab button, the focus will move to next cell on the same row.
Code for Ascii
Private Sub flexgrid_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
flexgrid.Text = flexgrid.Text & Chr(KeyAscii)
Case 46 'Dot
flexgrid.Text = flexgrid.Text & Chr(KeyAscii)
Case 8
If Len(flexgrid.Text) > 0 Then
flexgrid.Text = Left(flexgrid.Text, (Len(flexgrid.Text) - 1))
End If
Case Else
KeyAscii = 0
Beep
End Select
End Sub
How to do this.
And also how to change the particular cell background color.
Code
For i = 1 To flexgrid.Rows - 1
flexgrid.TextMatrix(i, 33) = vbred 'It's giving value like '255'
flexgrid.TextMatrix(i, 33) = .CellBackColor = vbred 'It's giving value 'False'
Next i
Any ideas & suggestion...?
To move the selected column use the KeyDown (or KeyUp if you prefer) event and place your code there.
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = Asc(vbTab) Then
If MSFlexGrid1.Col < MSFlexGrid1.Cols - 1 Then
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
End If
End If
End Sub
To change the cell background color first set the cell, then set the CellBackColor.
flexgrid.Row = i
flexgrid.Col = 33
flexgrid.CellBackColor = vbRed

VB6 ImageList Frm Code Generation

Note: This is probably a shot in the dark, and its purely out of curiosity that I'm asking.
When using the ImageList control from the Microsoft Common Control lib (mscomctl.ocx) I have found that VB6 generates FRM code that doesn't resolve to real property/method names and I am curious as to how the resolution is made. An example of the generated FRM code is given below with an ImageList containing 3 images:
Begin MSComctlLib.ImageList ImageList1
BackColor = -2147483643
ImageWidth = 100
ImageHeight = 45
MaskColor = 12632256
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 3
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":0054
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":3562
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":6A70
Key = ""
EndProperty
EndProperty
End
From my experience, a BeginProperty tag typically means a compound property (an object) is being assigned to, such as the Font object of most controls, for example:
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 10950
ClientLeft = 60
ClientTop = 450
ClientWidth = 7215
BeginProperty Font
Name = "MS Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = -1 'True
Strikethrough = 0 'False
EndProperty
End
Which can be easily seen to resolve to VB.Form.Font.<Property Name>.
With ImageList, there is no property called Images. The GUID associated with property Images indicates type ListImages which implements interface IImages. This type makes sense, as the ImageList control has a property called ListImages which is of type IImages. Secondly, properties ListImage1, ListImage2 and ListImage3 don't exist on type IImages, but the GUID associated with these properties indicates type ListImage which implements interface IImage. This type also makes sense, as IImages is in fact a collection of IImage.
What doesn't make sense to me is how VB6 makes these associations. How does VB6 know to make the association between the name Images -> ListImages purely because of an associated type (provided by the GUID) - perhaps because it's the only property of that type? Secondly, how does it resolve ListImage1, ListImage2 and ListImage3 into additions to the collection IImages, and does it use the Add method? Or perhaps the ControlDefault property?
Perhaps VB6 has specific knowledge of this control and no logical resolution exists?
You can see what's going on with this fairly contrived example. Start with an ActiveX project and add Class1 and mark it as Persistable = 1
' Class1
Option Explicit
Private m_sText As String
Property Get Text() As String
Text = m_sText
End Property
Property Let Text(sValue As String)
m_sText = sValue
End Property
Private Sub Class_ReadProperties(PropBag As PropertyBag)
With PropBag
m_sText = .ReadProperty("txt", "")
End With
End Sub
Private Sub Class_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "txt", m_sText, ""
End With
End Sub
Add UserControl1
' UserControl1
Option Explicit
Private m_oData As Class1
Property Get Data() As Class1
Set Data = m_oData
End Property
Private Sub UserControl_Initialize()
Set m_oData = New Class1
m_oData.Text = "this is a test"
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
Set m_oData = .ReadProperty("rs", Nothing)
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "rs", m_oData, Nothing
End With
End Sub
Add Form1 and place a UserControl1 on it as save it. You might wan to add Module1 for Sub Main
' Module1
Sub Main()
With New Form1
.Show
End With
End Sub
Here is my Form1.frm file
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2400
ClientLeft = 48
ClientTop = 432
ClientWidth = 3744
LinkTopic = "Form1"
ScaleHeight = 2400
ScaleWidth = 3744
StartUpPosition = 3 'Windows Default
Begin Project1.UserControl1 UserControl11
Height = 516
Left = 924
TabIndex = 0
Top = 588
Width = 1020
_ExtentX = 1799
_ExtentY = 910
BeginProperty rs {326250A4-CA0D-4F88-8F20-DAA391CF8E79}
txt = "this is a test"
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
So UserControl1 determines that object m_oData is persisted as property rs in its WriteProperty overload. Class1 determines that its m_sText member variable (or Text public property) is persisted as txt member in the IPropertyBag the frm is passing. There is nothing that requires public property names to match internal property bag names. I would personally use shorted IDs just to minimize bloat (if possible with VB6 at all).
I am guessing that the GUID ({2C247F25-8591-11D1-B16A-00C0F0283628}) points to the associated ImageList control and ListImage1, ListImage2, etc... is just there to enumerate all the images.
It's kind of like an early version of WPF associated controls (e.g. a TextBox can reference its enclosing grid for placement).

Resources