Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all 21238 articles
Browse latest View live

visual basic

$
0
0
When you press a button I want to turn labels (with their current value) into textboxes.

Compiler Error : Argument Not Optional

$
0
0
Hello.
I am getting a compiler error : Argument Not Optional. Please help.

here is code :

Code:

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset


Private Sub cmdAdd_Click()
rs.AddNew
Frame1.Visible = True
cmdAdd.Enabled = False
cmdUpdate.Visible = True
End Sub



Private Sub cmdSearch_Click()
n = Val(InputBox("Enter th Book Id to Search"))
rs.MoveFirst
Do While rs.EOF = False
If rs.Fields(0) = n Then
Frame1.Visible = True
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
Exit Do
End If
rs.MoveNext
Loop
End Sub

Private Sub cmdUpdate_Click()
rs.Fields(0) = Val(Text1.Text)
rs.Fields(1) = Text1.Text
rs.Fields(2) = Text1.Text
rs.Fields(3) = Val(Text4.Text)
rs.Update
End Sub

Private Sub Form_Load()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Amit\Documents\book.mdb;Persist Security Info=False"
conn.Open
Set rs = New ADODB.Recordset
rs.ActiveConnection = conn
rs.Source = "Select * from book"
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open
rs.Move
End Sub

Download a web page into a text file

$
0
0
Hello !

In an application I declare:

Code:

Public Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

use the function:

Code:

Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function

and:

Code:

URLDownloadToFile 0, "https://some_url.com", "TextFile.txt", 0, 0
.....
.....

to download a, not so large, web page into a text file.

When I start the application the first time often nothing happens. (Nothing is downloaded !)

But if I first manually, with a web browser, open the same website, close it again and thereafter re-run the application, everything works as it should and then every attempt !

At least that's the case in design mode....

What can I add to the application to make it download the web page at the first start, without having to preopen the website ?

Best regards and thanks in advance.

/Kalle

VB6 + Mschart: HELP. Titles not easy to red / how to change resolution?

$
0
0
Hi there.
Please look at these pictures.
The data titles are very difficult to read.
Maybe I can change the resolution of mschart or something?

Name:  Dibujo1.jpg
Views: 11
Size:  19.2 KBName:  Dibujo2.jpg
Views: 9
Size:  25.4 KBName:  Dibujo3.jpg
Views: 10
Size:  17.9 KB
Attached Images
   

[RESOLVED] you tried to execute a query that does not include the specified expression why?

$
0
0
i am getting this error why?
Code:

you tried to execute a query that does not include the specified expression as part of an aggregate 'TempDate'
what is wrong with the code?
Code:

Dim DateToday As Date
DateToday = Format(Now, "DD/MM/YYYY")

Dim RsA As New ADODB.Recordset
RsA.Open "Select TempCash.TempDate ,Sum(TempCash.TempPay) AS SumOfTempPay FROM TempCash Where TempMethod = 'Cash' AND TempDate = #" & DateToday & "#", CN

tnx for any help
salsa31

Need help taking a screenshot

$
0
0
Some time ago I have found this code somewhere in the vastness of the internet:

Code:

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long


Private Sub Command1_Click()

Picture1.AutoRedraw = True
       
BitBlt Me.Picture1.hDC, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ Screen.TwipsPerPixelY, GetDC(GetDesktopWindow), 0, 0, vbSrcCopy
       
ReleaseDC GetDesktopWindow, GetDC(GetDesktopWindow)

SavePicture Picture1.Image, App.Path & "\Screenshot.bmp"

End Sub

I like this method because the code is short and it is pretty easy to understand it but there is one problem with it. After screenshot is saved to the BMP file screenshot is cropped to the size of PictureBox so it is no more a full image of the screen. So first question will be how to get full image not cropped? And the second question will be is it possible to write image directly to the BMP file instead of first writing it to the PictureBox?

Thank you in advance for any help you can provide!

Finding a substring in a Word document

$
0
0
Using vb6, eventually I want to find where a month is first mentioned in a Word document and replace it with something else. It could be any valid month so I'll be comparing with a substring of eg "JanuaryFebruaryMarch...". The code below is self explanatory. I am using a short test string for now and as you can see from my remarks it works but not when I'm trying to match with a substring. I'd like some ideas that would fit into the structure I have.

Code:

'Project > References > Microsoft Word 14 Object Library
Option Explicit
Dim aPath As String
Dim aName As String
Dim FileName$
Dim wrdApp As Word.Application
Dim Finished As Boolean

Dim fMonth As String
Dim Looper As Integer


Private Sub Form_Load()
    aPath = "C:\Users\Alan\Documents\"
    Set wrdApp = CreateObject("word.application") ' that was needed in full test to allow close
End Sub

Private Sub Command1_Click()  ' edit now
    aName = aPath & "1InTest.docx"
    FileName$ = aName
    With wrdApp
        .Documents.Open FileName$
        .WindowState = wdWindowStateMaximize
        .Visible = True
        .Selection.Find.Text = "ARY"  '#### this works

        '.Selection.Find.Text = Mid("ARYOh", InStr(1, "ARYOh")) '####this does not
         
        .Selection.Find.Replacement.Text = "New Text"
        .Selection.Find.Execute Replace:=wdReplaceOne
       
    End With
       
       
   
           
    Finished = True 'if false, exits program without trying to close an unopened file

End Sub

Private Sub Command2_Click() 'CLOSE
    If Finished = True Then
        wrdApp.ActiveDocument.Close
        wrdApp.Quit
    End If
    Unload Me
End Sub

Wait for a smart card with SCardGetStatusChange ... and so?

$
0
0
Good afternoon!

I'm trying to create a really simple code to register name and surname from some users' smart cards.

I'm able to retrieve all data I need (maybe), but I'd like that this routine starts only when a card is inserted.

Somebody knows how SCardGetStatusChange works? I read many articles but I didn't understand yet!

Please!

Thx in advance!

[RESOLVED] Need help taking a screenshot

$
0
0
Some time ago I have found this code somewhere in the vastness of the internet:

Code:

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long


Private Sub Command1_Click()

Picture1.AutoRedraw = True
       
BitBlt Me.Picture1.hDC, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ Screen.TwipsPerPixelY, GetDC(GetDesktopWindow), 0, 0, vbSrcCopy
       
ReleaseDC GetDesktopWindow, GetDC(GetDesktopWindow)

SavePicture Picture1.Image, App.Path & "\Screenshot.bmp"

End Sub

I like this method because the code is short and it is pretty easy to understand it but there is one problem with it. After screenshot is saved to the BMP file screenshot is cropped to the size of PictureBox so it is no more a full image of the screen. So first question will be how to get full image not cropped? And the second question will be is it possible to write image directly to the BMP file instead of first writing it to the PictureBox?

Thank you in advance for any help you can provide!

Printing graphics, text, etc. with high clarity. Is it possible?

$
0
0
Hello!

I have been trying to get a print that is as crisp, clear, and legible as what I am getting from MS Word.
I've tried a picture in several formats: bmp, metafile, gif, jpeg, png.

I have tried placing these pictures in a PictureBox, and Image control, etc..
I have used bitblt to copy to other PictureBoxes, printer, etc., API calls, methods with the clipboard, without the clipboard.
I have tried several methods, many from posts found here.
Yet, none have equaled the quality I see from a simple paste command to a MSWord document.

Because of the printout I get from MSWord, I can conclude that my picture source, and printer are not the issue.
So, by reason, my methods are incorrect.

I have determined that the metafile seems to provide the best picture, but here I have included a JPEG file due to size constraints up the upload method.

I haven’t posted any code with this, because at this point, obviously, any method I have chosen is incorrect.
I have spent many hours trying to achieve the desired results, and have deleted, discarded, etc. a lot of code.
I need to start over with this task.

Can someone please help?


Thanks
Attached Images
 

[Help] Skew image in vb6 like 3D

Where is the VB6 Student Edition?

$
0
0
I know this has been covered before as I searched thru the old posts, but I cannot find where the student edition went. I have a retiree friend who want s to learn VB6 but neither of us can find the older VB6 install. He started doing the free version from Microsoft, A 7 GB INSTALL!!!! Holy Cow!!
I told him that is not the VB6 edition. He wants to write code that can be ported to Mac and Linux too.
An older previous posting gave a link to a German university but that link is dead. And I could not find anything on eBay either.
Anybody know how to get this?
Thanks much.

Time Difference

$
0
0
Hi

I have DatetIme field . I want to subtract this field from Current Time & check the difference . I fit is greater than 6 Hrs it should give message.

Thanks

WebBrowser GET method hook

$
0
0
Hi, i'm trying to hook the all GET query method during the page loading. but what i know is that 'BeforeNavigate' method for the first url query. i mean as soon as i hit the specific url which is include couple of urls, frams and script pages. so, i want to modify that url at my own parameters. any ideas ? thanks in advance.

Cheers.

A WIA Image

$
0
0
Hi all,
I have a reference to the well known WIA library that provides many benefits to users who need to handle images in many ways. In my case, I just want to set a picture position inside a Form and to be able to display it with transparency. To solve the first issue I set the png file inside a vb native Picture control although I feel that wia library itself should have somewhere some properties related to the image position.
Regarding transparency, even the png background is transparent it is displayed (inside my picture control or in form, it doesn't matter) as white. Is it any setting that allows me to preserve and display its original transparency? Below is my small routine within a click event. Thank you in advance.
Code:

Private Sub Command1_Click()
    Dim myPic As WIA.ImageFile
    Set myPic = New WIA.ImageFile
   
    myPic.LoadFile App.Path & "\Ok.png"
Set Picture1.Picture = myPic.FileData.Picture

End Sub


2 or more sounds simultaneously

$
0
0
I'v been toying around with sounds as part of my projeckt. I really want to have background music running as well as sound effects.

I'm using sndPlaySound Lib "winmm.dll" and I think I uderstand that this is a single channel as in I can't get two sounds in with it.
I'v also been looking at Mmsystem.dll but my Visual basic 6.0 can't find the dll

So i'm left with yet another question for you brilliant and friendly people.
How can I play background music and sound effects.


Code:

Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
      "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As _
      Long) As Long
  Const SND_ASYNC = &H1
  Const SND_NODEFAULT = &H2

Code:

SoundName$ = "nom.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)

My background music starts with the 2nd form. It's my starting "screen" for the game and it does not get shut down when the game window is running, just get put in the background. It's the same code I use for the background music and sound effects.

i need to improve aplication.inputbox

$
0
0
hi, how can improve this macro. This macro do operation rows within a matrix.
I need to input "a" inside of the inputbox, i.e if the position or range of "a" is A5 , i would like to input A5 as a range in the inputbox.
It is hard to work with "a" as active cell.
PHP Code:

Sub FieldOperation(): On Error Resume Next
Dim Field 
As RangeAs Range
Dim rOffset1 
As IntegercOffse1t As IntegerrOffset2 As IntegercOffse2 As Integer


Set Field 
Application.InputBox("After run macro: Human do not forget to have a selected row in spreadsheet excel and a given value in the first cell of selected row in spreadsheet." Chr(10) & _
"Note: Type ( , ) or hold Ctrl to separate rows. Please follow the Example."Title:="Please select two rows within a matrix", Default:="Example: A1:C1, A2:C2"Type:=8)



ActiveCell
rOffset1 
Field.Areas(2).Row Field.Areas(1).Row
cOffset1 
Field.Areas(2).Column Field.Areas(1).Column

For Each n In Field.Areas(1)
   
rOffset2 n.Row Field.Areas(1).Row
   cOffset2 
n.Column Field.Areas(1).Column
   ActiveCell
.Offset(rOffset2cOffset2) = n.Offset(rOffset1cOffset1) * a
Next
End Sub 

[RESOLVED] A WIA Image

$
0
0
Hi all,
I have a reference to the well known WIA library that provides many benefits to users who need to handle images in many ways. In my case, I just want to set a picture position inside a Form and to be able to display it with transparency. To solve the first issue I set the png file inside a vb native Picture control although I feel that wia library itself should have somewhere some properties related to the image position.
Regarding transparency, even the png background is transparent it is displayed (inside my picture control or in form, it doesn't matter) as white. Is it any setting that allows me to preserve and display its original transparency? Below is my small routine within a click event. Thank you in advance.
Code:

Private Sub Command1_Click()
    Dim myPic As WIA.ImageFile
    Set myPic = New WIA.ImageFile
   
    myPic.LoadFile App.Path & "\Ok.png"
Set Picture1.Picture = myPic.FileData.Picture

End Sub

[RESOLVED] Unicode filename

$
0
0
I have searched the Internet for solution but I haven't found any.

Like I said in title, I want to give unicode filename to some file, nevertheless if I do that directly (for example with command "Open [file] For Output ..."), or renaming it later (i.e. command "Name [file] As [newfile]"), because it does not work in both cases.

Here is example code where I want to extract YouTube title (which in this case is in Russian) and use that as filename (put this code in module and run):
VB Code:
  1. Private Const INTERNET_OPEN_TYPE_DIRECT = 1
  2. Private Const INTERNET_OPEN_TYPE_PROXY = 3
  3. Private Const IF_FROM_CACHE = &H1000000
  4. Private Const IF_MAKE_PERSISTENT = &H2000000
  5. Private Const IF_NO_CACHE_WRITE = &H4000000
  6. Private Const BUFFER_LEN = 256
  7. Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
  8. Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
  9. Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
  10. Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
  11.  
  12. Public Function Inet(sURL As String, scUserAgent As String, Optional sProxy As String, Optional sHeaders As String) As String
  13. Dim hOpen As Long, hFile As Long, sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String, lReturn As Long
  14. On Error GoTo Error
  15. If Not InStr(1, sProxy, ":") > 0 And Not InStr(1, sProxy, ".") > 0 Then hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0) Else: hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PROXY, sProxy, vbNullString, 0)
  16. If sHeaders = "" Then hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, IF_NO_CACHE_WRITE, ByVal 0&) Else: hFile = InternetOpenUrl(hOpen, sURL, sHeaders, CLng(Len(sHeaders)), IF_NO_CACHE_WRITE, ByVal 0&)
  17. If hFile Then
  18. iResult = InternetReadFile(hFile, sBuffer, BUFFER_LEN, lReturn)
  19. sData = sBuffer
  20. Do While lReturn <> 0
  21. iResult = InternetReadFile(hFile, sBuffer, BUFFER_LEN, lReturn)
  22. sData = sData + Mid(sBuffer, 1, lReturn)
  23. Loop
  24. End If
  25. InternetCloseHandle hFile
  26. InternetCloseHandle hOpen
  27. Inet = sData
  28. Error: Exit Function
  29. End Function
  30.  
  31. Sub Main()
  32. Dim strUserAgent As String, strName As String
  33. strUserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:35.0) Gecko/20100101 Firefox/35.0"
  34. strName = Split(Split(Inet("https://www.youtube.com/watch?v=gi7gs4EGnCI", strUserAgent), "<title>")(1), " - YouTube")(0)
  35. Open strName & ".txt" For Output As #1
  36. Print #1, strName
  37. Close #1
  38. End Sub
Result is:

which is not valid.
But, in that file is also written YouTube title, and it is in it's original state:


Does somebody know solution for this problem? Thanks in advance!

Shape Blinks While Moving With Timer!

Viewing all 21238 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>