Jump to content

[VB 6.0] Menus - Abrir, Guardar Como..., Imprimir


NameException
 Share

Recommended Posts

Boas!!!

Tou a fazer uma aplicação em VB, mas n tou a conseguir programar os itens do menu Ficheiro, Abrir, Guardar Como..., e Imprimir....

Neste momento, o erro k me surge refere-se a "FileName".... quando se clica no botão "OK", em Abrir e Guardar Como... O código k experimentei foi....

Private Sub cmdOK_Click()

    If (Right$(Dir1.Path, 1) = "\") Then  FileName$ = Dir1.Path + File1.FileName

    Else
        FileName$ = Dir1.Path + "\" + File1.FileName

    End If
    
    Open FileName$ For Input As #1
    frmEditor.txtPad.Text = Input$(LOF(1), #1)
    Close #1
    Unload frmLoad
End Sub

Quanto ao Imprimir, não faço a minima ideia como o programar..... 😞!

Se alguém me puder ajudar.... Agradecia....

Obrigado!!!!

Link to comment
Share on other sites

Eu tenho axim.... Para tentar programar o menu "Guardar como..." 

Public Sub FileName()
    If (Right$(frmSalvar.Dir1.Path, 1) = "\") Then
        frmSalvar.txtFileName.Text = frmSalvar.Dir1.Path + frmSalvar.File1.FileName
    Else
        frmSalvar.txtFileName.Text = frmSalvar.Dir1.Path + "\" + frmSalvar.File1.FileName
    End If
End Sub

Private Sub cmdCancelar_Click()
    Unload frmSalvar
End Sub

Private Sub cmdOK_Click()
    If (Right$(Dir1.Path, 1) = "\") Then
        FileName$ = Dir1.Path + File1.FileName
    Else
        FileName$ = Dir1.Path + "\" + File1.FileName
    End If
    
    Open FileName$ For Input As #1
        frmEditor.txtPad.Text = Input$(LOF(1), #1)
    Close #1
        Unload frmLoad
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    Call FileName
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
    Call FileName
End Sub

Private Sub File1_Click()
    Call FileName
End Sub

'Private Sub mnuArquivoItem_Click(Index As Integer)
'Select Case Index
'    Case 0  'Abrir
'        frmAbrir.Show
'    Case 1  'Salvar
'        frmSalvar.Show
'    Case 2  'Separador
'    Case 3  'Sair
'        End
'End Select
'End Sub

mas dá erro ao cliclar em "ok"....

"Compile error:

Type-declaration character does not match declared data type"

Private Sub cmdOK_Click()    ' <- !!!!!!!!!!!!!!!!!!!!AQUI É QUE DÁ O ERRO!!!!!!!!!!!!!!
    If (Right$(Dir1.Path, 1) = "\") Then
        FileName$ = Dir1.Path + File1.FileName
    Else
        FileName$ = Dir1.Path + "\" + File1.FileName
    End If
    
    Open FileName$ For Input As #1
        frmEditor.txtPad.Text = Input$(LOF(1), #1)
    Close #1
        Unload frmLoad
End Sub
Link to comment
Share on other sites

Deslculpa, Tiago Salgado... Tens toda a razão eu não tava bem a ver o que era a commond Dialog... mas ja a estou a usar... Mas não estou a conseguir abrir nem guardar ficheiro na minha aplicação... pois quando clico "ok" simplesmente sai da commond Dialog respectiva...

Como é que posso pôr aki imgens no forum para ilustar melhor a minha duvida??

Link to comment
Share on other sites

CommonDialog1.CancelError = False
CommonDialog1.DialogTitle = "Insira Imagem..."
CommonDialog1.Filter = "Todas as Imagens |*.jpg;*.jpeg;*.gif;*.bmp"
CommonDialog1.FilterIndex = 0
CommonDialog1.ShowOpen

MsgBox CommonDialog1.FileName

Ve se isto te ajuda...senao eu tento fazer um project com a utilizaçao da CommonDialog e forneço-te

Link to comment
Share on other sites

Agora tenho axim:

Private Sub mnuAbrir_Click()
    CommonDialog2.ShowOpen
End Sub

Private Sub mnuGuardar_Como_Click()
    CommonDialog2.ShowSave
End Sub

Depois de abrir a common Dialog "Abrir" e quando clico "ok" não faz nada.... Será por não ter especificado "Tipos de Ficheiro" ???? Como posso fazer?????

O memmo acontece para a common Dialog "Guardar como..."

http://img109.imageshack.us/img109/3264/abrir0gu.png

EDIT: GMRB, usa a ferramenta GeSHI quando postares código! Assim o código fica mais legível (como poderás verificar).

Cumprimentos brinkaero

Link to comment
Share on other sites

Agora tenho axim:

Private Sub mnuAbrir_Click()

    CommonDialog2.ShowOpen

End Sub

Private Sub mnuGuardar_Como_Click()

    CommonDialog2.ShowSave

End Sub

Depois de abrir a common Dialog "Abrir" e quando clico "ok" não faz nada.... Será por não ter especificado "Tipos de Ficheiro" ???? Como posso fazer?????

O memmo acontece para a common Dialog "Guardar como..."

http://img109.imageshack.us/img109/3264/abrir0gu.png

Não faz nada porque tu não estás a dizer que tem que fazer. Tu apenas tas a fazer o Open da Dialog mas não tas a dizer que qd carregares em OK tenha q fazer algo mais... A seguir ao CommonDialog2.ShowOpen tens q por o código que te poe o conteudo do ficheiro onde tu queiras.

Link to comment
Share on other sites

Boas!

Estou a fazer um editor de texto e fiz um código para uma commonDialog para abrir e escolher um ficheiro...

codigo:

Private Sub mnuopen_Click(Index As Integer)
Dim numficheiro
CommonDialog1.ShowOpen
numficheiro = FreeFile
If CommonDialog1.FileName <> "" Then
    Open CommonDialog1.FileName For Input As numficheiro
    Text1.Text = Input(LOF(numficheiro), numficheiro)
    Close #numficheiro
End If
End Sub

mas agr keria defenir que essa commonDialog só abri-se ficheiros *.txt ... que código devo por?  ?

cumps[]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.