Visual Basic 6 help urgently needed

C

Carl

Hi there guys

I'm currently developing a word processor, based around a rich text box
and a common dialog control, using visual basic 6, and have come across
a couple of problems, I would be very grateful if anyone could help
out.

Firstly the word processor uses both command button and drop down menus
As part of the project each of the buttons/menu options has to be
enabled/disabled appropriately. Is there a more modular way of
enabling/disabling buttons/menu selections, as i'm currently writing
huge amounts of code for each button/menu selection state. For
example:

Private Sub Form_Load()
Call LoadButtons
End Sub

Private Sub LoadButtons()
cmdPaste.Enabled = False
cmdSave.Enabled = False
cmdCut.Enabled = False
cmdCopy.Enabled = False
cmdClearClip.Enabled = False
cmdFont.Enabled = False
cmdExit.Enabled = True
cmdOpen.Enabled = True
cmdNew.Enabled = True
End Sub

There are another five sets of these button state routines, all of
which need to be called at various times.

Secondly, using the common dialog control I have run into an error when
trying to save. The documents are only saved in the format requested
(either txt or rtf) if I manually add the .txt or .rtf at the end of
the file name in the save window. If I dont enter the file extentions
the files are saved as "File" ie the icon with a window inside. Below
is the code used to save documents:

Private Sub Save()
On Error GoTo SaveError

With cdlDialog
.CancelError = True
.Filter = "Text Files (*.txt)|*.txt|Rich Text Files (*.rtf)|*.rtf"
.FilterIndex = 2
.ShowSave

End With

If cdlDialog.FilterIndex = 1 And _
FontChange = True Then
MsgBox "Will result in a loss of format", vbInformation
End If

rtbInput.SaveFile cdlDialog.FileName
MsgBox "File saved as " & cdlDialog.FileName
SaveChange = False
Exit Sub

SaveError:
Dim intRetVal As Integer
intRetVal = MsgBox("The file has not been saved. Try again",
vbRetryCancel + vbQuestion)
If intRetVal = vbRetry Then
Resume
Else
cmdExit.SetFocus
End If

End Sub

Thanks again for any help
 
D

Douglas J. Steele

You might be better off asking in one of the newsgroups related to VB (they
all start microsoft.public.vb)

There are subtle differences in terms of how you interact with controls in
VB6 and in VBA (which is what Access uses)
 
T

Terry Kreft

I would have set the buttons up as part of a control array you could then do
something like

Private Sub SetButtons(ButtonState As Variant)
Dim intX As Integer

' You'd do checks here like making sure you've got an array _
and that the array bounds match the control array bounds

For intX = LBound(ButtonState) To UBound(ButtonState)
Me.cmdButtons(intX).Enabled = ButtonState(intX)
Next
End Sub

Then you could do the following

Private Sub Form_Load()
Call SetButtons(Array(0, 0, 0, 0, 0, 0, -1, -1, -1))
End Sub

If you wanted a different set of enabled states then you could do the
following
' ...
Call SetButtons(Array(-1, 0, 0, -1, 0, 0, -1, 0, -1))

or any of the other permutations open to you.

On the Save dialog I'm guessing you're using the control, if so dump it and
get a code solution from one of the MVP websites at www.mvps.org. They're
much more reliable than the ActiveX control.

Having said all that this is a NG for Access not VB.
 
C

Carl

Thank you for your help

Terry said:
I would have set the buttons up as part of a control array you could then do
something like

Private Sub SetButtons(ButtonState As Variant)
Dim intX As Integer

' You'd do checks here like making sure you've got an array _
and that the array bounds match the control array bounds

For intX = LBound(ButtonState) To UBound(ButtonState)
Me.cmdButtons(intX).Enabled = ButtonState(intX)
Next
End Sub

Then you could do the following

Private Sub Form_Load()
Call SetButtons(Array(0, 0, 0, 0, 0, 0, -1, -1, -1))
End Sub

If you wanted a different set of enabled states then you could do the
following
' ...
Call SetButtons(Array(-1, 0, 0, -1, 0, 0, -1, 0, -1))

or any of the other permutations open to you.

On the Save dialog I'm guessing you're using the control, if so dump it and
get a code solution from one of the MVP websites at www.mvps.org. They're
much more reliable than the ActiveX control.

Having said all that this is a NG for Access not VB.
 
C

Carl

Thank you for your help

Terry said:
I would have set the buttons up as part of a control array you could then do
something like

Private Sub SetButtons(ButtonState As Variant)
Dim intX As Integer

' You'd do checks here like making sure you've got an array _
and that the array bounds match the control array bounds

For intX = LBound(ButtonState) To UBound(ButtonState)
Me.cmdButtons(intX).Enabled = ButtonState(intX)
Next
End Sub

Then you could do the following

Private Sub Form_Load()
Call SetButtons(Array(0, 0, 0, 0, 0, 0, -1, -1, -1))
End Sub

If you wanted a different set of enabled states then you could do the
following
' ...
Call SetButtons(Array(-1, 0, 0, -1, 0, 0, -1, 0, -1))

or any of the other permutations open to you.

On the Save dialog I'm guessing you're using the control, if so dump it and
get a code solution from one of the MVP websites at www.mvps.org. They're
much more reliable than the ActiveX control.

Having said all that this is a NG for Access not VB.
 
L

Larry Linson

Douglas J. Steele said:
You might be better off asking in one of the newsgroups related to VB
(they all start microsoft.public.vb)

There are subtle differences in terms of how you interact with controls in
VB6 and in VBA (which is what Access uses)

Actually, I wouldn't call the differences "subtle." The object model for
Forms and Controls in the separate VB6 product is different than the object
model for Forms and Controls in Access.

As an example, Access Forms and Controls have data-related events that VB6
just does not have, such as BeforeUpdate and AfterUpdate, two events that I
use frequently in database work. The core library of VB6 is the same
VBA6.DLL that is used in some versions of Access, but the language
statements being the same do not make the same code work properly on
different object models.

Larry Linson
Microsoft Access MVP
 
D

Douglas J. Steele

Larry Linson said:
Actually, I wouldn't call the differences "subtle." The object model for
Forms and Controls in the separate VB6 product is different than the
object model for Forms and Controls in Access.

As an example, Access Forms and Controls have data-related events that VB6
just does not have, such as BeforeUpdate and AfterUpdate, two events that
I use frequently in database work. The core library of VB6 is the same
VBA6.DLL that is used in some versions of Access, but the language
statements being the same do not make the same code work properly on
different object models.

Yeah, you're right, most aren't that subtle.

I was likely thinking specifically about the use the Text property. In VBA,
the text box must have focus, or referring to the its Text property will
raise an error. In VB, you can always use the Text property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top