Tracker
 ASP PHP JavaScripts MySQL MS Access MSSQL VISUAL BASIC Subjects/Titles Post Text/Content
HOME    TRACKER    Visual Basic

# Code For Factorial

## I searched some of the other threads for info on factorials, but I couldn't find anything simple enough. What I have right now is the closest thing I can come to for a factorial:Private Sub cmd_exc_Click()'! function (not working yet) If Not (IsNumeric(txtbox1)) Then MsgBox "Valid characters only!" Exit Sub End If Dim facremain facremain = Val(txtbox1) Dim facresult facresult = Val(txtbox1) Do Until facremain = 0 Val(txtbox1) = Val(txtbox1) * (facremain - 1) facremain = facremain - 1 Loop lbl_answer.Caption = facresultEnd FunctionIt doesnt work so far, can anyone alter this code so it will work?Try to keep it as simple as possible. Thanks...

Factorial
I have a list of 7 items, I would like to see all the different ways the list can be arranged.

One idea is as follows, but something elegant would be far more useful.

If wanting to see all the possible arrangements of the letters in the word cat:
for x = 1 to the length of the word cat
position(a) = x
for y = 1 to lenght of the word cat
if y <> x then
position(b) = y
end if
if position(b) is filled then
for z = 1 to lenght of the word cat
if z <> x then
if z <> y then
position(c) = z

etc. etc., of course, for a seven item list, the nested IF's and what nots become outrageous.

Can anyone offer any suggestions?

Factorial
Can somebody clarify how to program extraction of factorial values in VB.

When I write

X = n!
or X = (n -1)!

it appears that the program doesn't recognise " ! " as a mathematical operation, but only as an exclamation mark (as the expression becomes red with the compile error message "expected end of statement" only in the latter case).

Factorial
How would one do factorials:

5! = 120

using for loops?

Factorial
Can anyone tell me the code in vb for factorial using sub and class plz.

Factorial
A user will enter the number into a Text Box (txtFactorial) and the application will display the factorial of that number in a Label (lblFactorial).

What code is required in the cmdFactorial Command Button to accomplish this?

Factorial
please, can anybody help me about Factorial,I'm learning about vb6 and need know how to. I know that 3!=3*2*1.Thanks and sorry for my English

Factorial
Does any one know the VB representation of a "factorial." Either n! or x! on a decent calculator. example. 5! = 120
that is: 5 x 4 x 3 x 2 x 1 normally used with probability calculations etc.

How To Do Factorial In Vb??Need Help
The question is find factorial of a number.Receive input using inputbox and display using messagebox

How do i do it?If it is in C++ i know how it works but in Vb im kinda blur of how to use the module
this is what i do in module already

Public Function Factorial(Number As Integer) As Long
If Number < 1 Then
Factorial = 1
Else
Factorial = Number * Factorial(Number - 1)
End If
End Function

but my problem is how im going to use it in my main coding area
since im using an input box so bit blur and need help

How To Factorial A Number?
How do I use visual basic to work out say 5! (5 factorial, 1x2x3x4x5)
Is there a keyword or do I have to set up some loop.
I need to be able to factorial a variable number the user inputs

Factorial Function
I need to add this formula in Visual Basic
Any ideas how i could do that?

the formula is in one big curly bracket and it has 2 lines

before the bracket it says x!
after the bracket on the first line 1 if x = 0
second line x * (x-1)! if x> o

Help Findin The Factorial
OK, I want to have a simple program that will find the Factorial of a number. This is my code, but I'm not sure on how to loop it to keep going until 0. Don't understand? Here...

Code:
Private Sub Command1_Click()

Text2.Text = Text1.Text * (Text1.Text - 1)

End Sub

So if I put a Do/Loop, ex.

Code:

Do
Text2.text = Text1.Text * (Text1.Text -1)
Loop Until Text1.Text = 0

It loops forever and uses every last bit of prossesing speed! So what I need it to do is to find the Factorials of numbers.

Factorial:

5!= 5*4*3*2*1=120

Factorial Problem
i have posted this problem many times in many forums .. in vb c++ and java also
but no one could help me yet ,... well
i want to get the factorial of 666! and power of A^666 but when i calculate it ... overflow error accur or stack overflows

Global Events For Keyboard SCAN CODE && ASCII CODE Event Trapping?
OK, don't be mad at me, if this is a stupid question, but I'm quite new to VB, so here's my Q:
Is there any global event (not KeyUp/KeyDown/KeyPress) to trap keyboard keypresses with SCAN codes? It is very important to have the exact scan code. I want to use an API function to simulate the pressed keys on an other machine, and I need to have the scan code. By the way, API function calls won't do it for me, I need an EVENT! (I don't want to call functions over and over again e.g. in a timer event. This is too -slow-)
So if anyone out there can help me, please do!
You won't regret it!

Thanks to all....

Optimize For Fast Code Or For Small Code - Windows Error Not Responding
when a i try to make exe file
and try to compile with project properties compile
option optimize for fast code or optimize for small code
my application doesn't respond

works only with no optimization
otherwise NOT RESPONDIG

Sipi

Inno Setup Systemfiles-code... Need Help Making This Code Safe...
Hi,
I'm using Inno Setup now, but I don't understand something about the install of the system files

People told me you have to watch out with installing the needed system files for your program on a computer. But I don't understand exactly how it's safe.

I don't know anything about the system files, but I know my program needs them... I already put in the right visual basic system files which I downloaded because someone said that was important...

This code is very bad now, so, is there someone who can help me making it safe for other computers?

[Files]

Source: "c:vbfilesstdole2.tlb"; DestDir: "{sys}"; Flags: restartreplace uninsneveruninstall sharedfile regtypelib
Source: "c:vbfilesmsvbvm60.dll"; DestDir: "{sys}"; Flags: restartreplace uninsneveruninstall sharedfile regserver
Source: "c:vbfilesoleaut32.dll"; DestDir: "{sys}"; Flags: restartreplace uninsneveruninstall sharedfile regserver
Source: "c:vbfilesolepro32.dll"; DestDir: "{sys}"; Flags: restartreplace uninsneveruninstall sharedfile regserver
Source: "c:vbfilesasycfilt.dll"; DestDir: "{sys}"; Flags: restartreplace uninsneveruninstall sharedfile
Source: "c:vbfilescomcat.dll"; DestDir: "{sys}"; Flags: restartreplace uninsneveruninstall sharedfile regserver

Source: MSVCRT40.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile

Source: type.wav; DestDir: {app}; Flags: promptifolder
Source: Info.mdb; DestDir: {app}; Flags: promptifolder
Source: OfflineData-205.mdb; DestDir: {app}; Flags: promptifolder

Source: mscomctl.ocx; DestDir: {app}; Flags: promptifolder regserver
Source: RICHED32.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile
Source: richtx32.ocx; DestDir: {app}; Flags: promptifolder regserver
Source: MSSTDFMT.DLL; DestDir: {app}; Flags: promptifolder regserver
Source: msbind.dll; DestDir: {app}; Flags: promptifolder regserver
Source: VB5DB.DLL; DestDir: {app}; Flags: promptifolder
Source: MSREPL35.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile
Source: MSRD2X35.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile regserver
Source: expsrv.dll; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile
Source: vbajet32.dll; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile
Source: MSJINT35.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile
Source: MSJTER35.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile
Source: MSJET35.DLL; DestDir: {app}; Flags: restartreplace uninsneveruninstall sharedfile regserver
Source: DAO350.DLL; DestDir: {app}; Flags: promptifolder regserver

Source: Offline-MSN-2.0.exe; DestDir: {app}; Flags: promptifolder
Source: Offline-MSN-2.0.exe; DestDir: {app}; Flags: promptifolder

C++ Code To Visual Basic .net Code (32bit To 16bit Variables)
How do I change the following code to visual basic .net code...

long val;
long lowpart;
long hipart;
long table[9];

val = table[0];
lowpart = val & 0x0000FFFF;
hipart = val & 0xFFFF0000 >> 16;

Thanks!

Save Image Code Not Working Properly, (code Included)
I am trying to download an image file using DownloadFile and for whatever reason it's not downloading the file... I can make the image source link display... so I know that's working. It just isn't saving the file, this code used to work but not anymore apparently.

Anyone? Thanks!

VB 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 = TrueEnd Function Dim IMG As HTMLImgDim HTML As HTMLDocumentSet HTML = WebBrowser1.DocumentFor Each IMG In HTML.imagesIf InStr(IMG.src, "IMAGEKEYWORD") ThenDownloadFile IMG.src, App.Path & "image.jpg"Exit ForEnd IfNext

Moving Code To Code Behind File Causing Weird Problem...
Hi, I'm wondering if anyone has seen this before...

I wrote an aspx page that had both code and html in the same file. It worked fine. So I decided I would try and move the code to a .vb code behind file so I could link the code to multiple pages without having to edit a million pages of code to fix one issue.

So I move the code over and check dependancies and everything else and it works except for one thing.

I have a radioButtonList that is populated as I loop through a sql datareader. In the first aspx file it adds listitems once and goes onto the rest of the sub. In the vb file however, it seems to be loading everything into the RBL twice. It's as if it is reading the entire sub two times or something.

Any idea what would cause this, and how I can fix it. I'm stumped!

Thanks,
Chris

Please Review Code To Send Appointment From Access Code
This code is intended to send an appointment. When I double click my command button,in Access 97, nothing happens, and the appointment that I am send to myself does not appear. Any ideas, here is the code:

Private Sub Command94_Click()
Dim objOutlook As New Outlook.Application
Dim objAppoint As Outlook.AppointmentItem

objAppoint.Subject = "Subject-test appointment"
objAppoint.Body = "test appointment body"
objAppoint.Location = "Test Location"
objAppoint.Start = "6/6/02 2:00 pm"
objAppoint.End = "6/6/02 3:00 pm"
objAppoint.Send

End Sub

Thanks

Generate An Ascii Code From Vb Code And Vise Versa
hello,
i working in a project where i should read ascii code using the vb to generate the result on excel and vise versa, generate the ascii code using vb

any one have already did this?

thanks for the help

Help With Code!! Whats Wrong With This Code, Command5 Does Not Work.
this command does not work i have no idea could i get some help!!

Code:
Private Sub Command5_Click()
Dim score1 As Integer
Dim score2 As Integer
score1 = Label12.Caption
score2 = Label13.Caption
Dim bet As Integer
Dim money1 As Integer
Dim money2 As Integer
bet = Label14.Caption
money1 = Label10.Caption
money2 = Label11.Caption
If score1 > score2 Then
money2 = money2 - bet
money1 = money1 + bet
End If
If score2 > score1 Then
money1 = money1 - bet
money2 = bet + money2
End If
End Sub
if you need the whole code here it is......

Code:
Private Sub Command1_Click()
Timer1.Enabled = True
Label3.Caption = " "
End Sub

Private Sub Command2_Click()
Dim goodroll2 As Integer
Dim goodroll As Integer
goodroll = Label1.Caption
goodroll2 = Label2.Caption
If goodrolladd > 7 Then Label3.Caption = "Good Roll!!!"
Timer1.Enabled = False
If Label1.Caption = 1 And Label2.Caption = 1 Then Label3.Caption = "snake eyes!!"
If Label1.Caption = 1 And Label2.Caption = 1 Then Timer2.Enabled = True
End Sub

Private Sub Command3_Click()
Timer3.Enabled = True
Label3.Caption = " "
End Sub

Private Sub Command4_Click()
Dim goodrolltwo As Integer
Dim goodrolltwox2 As Integer
goodrolltwo = Label8.Caption
goodrolltwox2 = Label9.Caption
If goodrolladdtwo > 7 Then Label3.Caption = "Good Roll!!!"
Timer3.Enabled = False
If Label8.Caption = 1 And Label9.Caption = 1 Then Label3.Caption = "snake eyes!!"
If Label8.Caption = 1 And Label9.Caption = 1 Then Timer2.Enabled = True

End Sub

Private Sub Command5_Click()
Dim score1 As Integer
Dim score2 As Integer
score1 = Label12.Caption
score2 = Label13.Caption
Dim bet As Integer
Dim money1 As Integer
Dim money2 As Integer
bet = Label14.Caption
money1 = Label10.Caption
money2 = Label11.Caption
If score1 > score2 Then
money2 = money2 - bet
money1 = money1 + bet
End If
If score2 > score1 Then
money1 = money1 - bet
money2 = bet + money2
End If

End Sub

Private Sub Command6_Click()
Label14.Caption = Text3.Text
Text3.Text = " "
End Sub

Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Int((0 - 7 + 1) * Rnd + 7)
Label2.Caption = Int((0 - 7 + 1) * Rnd + 7)
End Sub

Private Sub Timer2_Timer()
Label3.ForeColor = Int((&HFFFFFF - &H400040 + 1) * Rnd + &H400040)
End Sub

Private Sub Timer3_Timer()
Label8.Caption = Int((0 - 7 + 1) * Rnd + 7)
Label9.Caption = Int((0 - 7 + 1) * Rnd + 7)
End Sub

Dlls Callback Work In P-Code But Not Native Code
OK I am so confussed I have made some software using some callbacks to a 3rd party Dlls. When I run the software compiled as P Code everytihng works fine. When I compile it as Native code it causes my software to exit. The problem is when I compile it as P code some of my other controls seem to stop working. I was just wondering if any body out there could tell me what is going on or how to fix this.
Thanks...

Another Novice Question: Typing Code As Text In Code???
I want a button to display vb code in a text box but having great problems typing the code as text and not actual code.

Steve-o

Menu Click (and Also Set Shortcut) From Code [resolved - Not By Code!]
Apparently the SHORTCUT of a menu is not available at runtime - argh...

Any API ways to get around this?

Also - doesn't seem like I can click a "menu" item from code - basically I want to trigger it's click event...

I guess I don't need this if I can set the shortcut from CODE!

Code Doesnt Work When Im Adding Some Other Code...[Solved]
Hi...
When im adding some code, all of the other code stops working
Here's the code:
VB Code:
If Left\$(strData, 9) = "USERLOGIN" Then        strArray2 = Split(strData, vbCrLf)        If ReadINI(App.Path & "users.ini", Right\$(strArray2(1), Len(strArray2(1)) - 13), "Password", vbNullString, 100) = Right\$(strArray2(2), Len(strArray2(2)) - 13) Then            '<:-) :WARNING: Empty String assignment updated to use vbNullString            '<:-) :PREVIOUS CODE : If ReadINI(App.Path & "users.ini", Right\$(strArray2(1), Len(strArray2(1)) - 13), "Password", "", 100) = Right\$(strArray2(2), Len(strArray2(2)) - 13) Then            If ReadINI(App.Path & "users.ini", Right\$(strArray2(1), Len(strArray2(1)) - 13), "Banned", vbNullString, 100) = "True" Then                '<:-) :WARNING: Empty String assignment updated to use vbNullString                '<:-) :PREVIOUS CODE : If ReadINI(App.Path & "users.ini", Right\$(strArray2(1), Len(strArray2(1)) - 13), "Banned", "", 100) = "True" Then                sckIntro(Index).SendData "BANNED"                Exit Sub            End If            If lstUsers.ListCount < 20 Then              sckIntro(Index).SendData "FULL"              Exit Sub            End If                 [b]     Dim i As Integer            For i = 0 To lstUsers.ListCount - 1            lstUsers.ListIndex = i            If lstUsers.Text = Right\$(strArray2(1), Len(strArray2(1)) - 13) Then            sckIntro(Index).SendData "ALREADYLOGGEDIN"            Exit Sub            Next i            End If[/b]                        sckIntro(Index).SendData "GOODLOGIN"            lstActions.AddItem "[" & Format\$(Time, "hh:mm:ss") & "] " & Right\$(strArray2(1), Len(strArray2(1)) - 13) & " has connected."            AddHScroll lstActions         Else 'NOT READINI(APP.PATH...            sckIntro(Index).SendData "BADLOGIN"            lstActions.AddItem "[" & Format\$(Time, "hh:mm:ss") & "] Someone tried to login with a bad username or password!"            AddHScroll lstActions        End If    End If
The code works fine without the bolded part...
When i add it, the code stops working and its giving errors!
What should i do?

Thanks!

Please Review Code To Send Appointment From Access Code
This code is intended to send an appointment. When I double click my command button,in Access 97, nothing happens, and the appointment that I am send to myself does not appear. Any ideas, here is the code:

Private Sub Command94_Click()
Dim objOutlook As New Outlook.Application
Dim objAppoint As Outlook.AppointmentItem

objAppoint.Subject = "Subject-test appointment"
objAppoint.Body = "test appointment body"
objAppoint.Location = "Test Location"
objAppoint.Start = "6/6/02 2:00 pm"
objAppoint.End = "6/6/02 3:00 pm"
objAppoint.Send

End Sub

Thanks

Getting A Code From A Text File And Running That Code At Runtime.
Hi,
Winamp avs plugins work this way. It reads the code from a .avs file and excutes it at runtime.

Do you know how to read a code from a text file and excute it at runtime.

for example.
C:windowsdesktop ext1.txt contains these lines.

______________
msgbox ("Hi")
______________

I want to read that file and excute that code at runtime with my programme.

Is it possible.

If it is please tell me how.

Regards,
Dasith

[code]If Timer.Enabled Then: Windows.Crash[/code]
This question is directed to anyone that has had the same problem as me but found a solution:

When I go out of my room I often leave the internet running, with MSN Messenger on. I made a program in VB that automatically replies to anyone that IMs me when I'm out. However, this uses a timer that ticks every 10 seconds, and it isn't uncommon to find that the program has crashed. I've experienced this problem before with the VB timer control when I made a motion sensor program for my webcam. Is there a way I can put together a few API calls (GetTickCount, Sleep, etc.) to simulate a timer, though with less chance of crashing my apps.

Sam

OLE Error Code 0x800a5077 Unknown COM Status Code
I know this is a FoxPro question but I'm not having any luck with the FoxPro Forum so I figured I'd talk to some real programmers.  Most of my work is in VB but this VFP Application came along and I'm not sure where to go from here.

I'm using Crystal 7 and VFP 6.0.   All of the Crystal reports run fine on the development machine from either Crystal or FoxPro.  The application ran fine on the user's machine but was unable to launch a Crystal Report from FoxPro without generating the "Unknown COM Status"  error.

I installed Crystal on the user's machine and the reports all run from Crystal.  I can browse the data and run the reports from Crystal too.  I even tried installing the entire FoXPro software on the user's machine but I'm still unable to run Crystal via the OCX from within the FoxPro App.  I've already installed the latest mdac update.

Any ideas?

How To Assign The Code Generated By A Bar-code Generator To A Variable Using VB?
I am having a specific code or you can say a stream of digits which is converted by a bar code generator into a bar code. So what i want to do is get this bar code in a variable using VB 6.0. So can you help me regarding this?

Quick File Listing Code (request For Code)
In all my years of programming I never really had to use/write any code that had to list many files (in a folder and all subfolders). Never really had a requirement to that other means were not better. But now I want to. In all these years I have seen questions asked a lot about how to do this type of thing and I never really paid much attention but I have seen many different ways. I was wondering, who has any nice *tight* reusable code that given a folder it can bring back all the files in that folder and all files in the subfolders of that folder. Of course I want it to be fast too. Also I would like to *not* use the FSO if possible as I know it is slow and not the best approach but if somebody has code that uses the FSO and feel they have coded it tight and it is fast I will be willing to give a try.

The main purpose of this code is going to be for my vcMP3 Player (which many of you know I have been working on and making better and better). I have just come to not like my PlayList Editor and thought about upgrading it (or at least adding an option to have an Advanced PlayList Editor or use the current one [will call is the Standard PlayList]). Really just want to be able to get pointed to a folder and then get all MP3 files listed under that folder and subfolders to make a complete list to quickly then let the user work with over my other playlist that just uses the common dialog box with multi file select. I also want to add other features to the Advanced Playlist editor but I have that under control.

Main thing though is I really want it to be as fast as possible and many of us know, many people have a LOT of mp3 files.

Clint LaFever (aka: DaVBMan)

Next, Previous Search .Please Critique My Code. How Could Code This Bertter
My code works and it does what I want it to. However I am not overly happy withit though cause my connection stays open the whole time the form is loaded.
If anyone knows how I could write the code a different way I would appreciate your input.
Also I never used any select statements such as
select * from tblpremiere where ItemID = ?????
What benefit does the select statement give me? My code is below

Call OpenConnect

Call display

End Sub

Private Sub cmdMoveFirst_Click()
'Making connection to DB

Call display

End Sub

Private Sub cmdMoveLast_Click()
'Making connection to DB

Call display

End Sub

Private Sub cmdMoveNext_Click()

On Error Resume Next
Call display
Else
Call display
End If

End Sub

Private Sub cmdMovePrevious_Click()

On Error Resume Next
Call display
Else
Call display
End If

End Sub

Private Sub cmdItemSearch_Click()

strMsg = "Enter an item number to look up and press enter." _
& Chr(13) & Chr(13) & "To cancel this operation press escape."
strTitle = "Item Number Look up"
strNumber = InputBox(strMsg, strTitle)

If IsNumeric(strNumber) Then
IntID = Val(strNumber)
Else
answer = MsgBox("You must enter Numeric Values only", vbOKOnly, "Invalid Entry")
End If

Call display
Exit Sub
Else
End If
Wend

End Sub

Private Sub display()

End Sub

Private Sub OpenConnect()

conn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source = C:Documents and SettingsDefaultDesktopVB2forcheckinAssetDB.mdb"
conn1.Open

End Sub

Private Sub CloseConnect()

conn1.Close

End Sub

Need Help: VB6 API Button Click Code Doesn't Work; VB.NET Code Does?!
I am baffled. My VB.NET code works, but my VB6 code does not. I need to know what is wrong with the VB6 code and why doesn't behave the same as the .NET code?

VB6 Code:
Code:
' in a BAS module
Public Declare Function SendMessage2 Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Long) As Long

Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const MK_LBUTTON = &H1

‘in a Class
Public Sub DoWindowAction(ByVal vlngHWND As Long)
Dim lngReturn As Long
lngReturn = SendMessage2(vlngHWND, WM_LBUTTONDOWN, MK_LBUTTON, 0)
lngReturn = SendMessage2(vlngHWND, WM_LBUTTONUP, 0, 0)
'lngReturn = SendMessage2(vlngHWND, BM_SETSTATE, 1, 0)
End Sub

The commented out line with the BM_SETSTATE gets me a little closer. But even with this in I need to set focus to the application that contains the button I am trying to click with vlngHWND and then move focus to another app. What is going on???

VB.NET code:
Code:

Friend Class API
<DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

Public Const WM_LBUTTONDOWN As Integer = &H201
Public Const WM_LBUTTONUP As Integer = &H202

End Class

'in a form
Private Sub ClickButton()
API.SendMessage(lngHWND, API.WM_LBUTTONDOWN, 1, 0)
API.SendMessage(lngHWND, API.WM_LBUTTONUP, 0, 0)
End Sub

Thanks,
Eric

Need Some Major Help Transfering Some GET FAVORITE Code Into History Code
hey every1 i really need some major help transfering some GET FAVORITE Code into history code this is the original code (help will be much apreciated)

module:
Code:
Option Explicit

Public Const MAX_PATH As Long = 260
Public Const INVALID_HANDLE_VALUE As Long = -1
Public Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
Public Const SHGFP_TYPE_CURRENT As Long = &H0
Public Const SHGFP_TYPE_DEFAULT As Long = &H1
Public Const CSIDL_FAVORITES As Long = &H6
Public Const CSIDL_COMMON_FAVORITES As Long = &H1F
Public Const MAX_LENGTH As Long = 260
Public Const S_OK As Long = 0
Public Const S_FALSE As Long = 1

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

'this is my type for passing and
'retrieving file search information
Public Type FILE_PARAMS
bRecurse As Boolean
bList As Boolean
bFound As Boolean
sFileRoot As String
sFileNameExt As String
sResult As String
nFileCount As Long
nFileSize As Double
End Type

Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpSectionName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Declare Function SHGetFolderPath Lib "shfolder.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long

Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long

Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
'--end block--'

form
Code:

Option Explicit

Private Sub Command2_Click()
Form1.WebBrowser1.Navigate Combo2.Text
End Sub

With ListView1

End With

End Sub

'toggle the sort order based on the column clicked
ListView1.SortOrder = Abs(ListView1.SortOrder = 0)
ListView1.Sorted = True

End Sub

Private Function SearchForFiles(FP As FILE_PARAMS) As Double

'local working variables
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
Dim nSize As Long
Dim sPath As String
Dim sRoot As String
Dim sTmp As String

sRoot = QualifyPath(FP.sFileRoot)
sPath = sRoot & "*.*"

'obtain handle to the first match
hFile = FindFirstFile(sPath, WFD)

'if valid ...
If hFile <> INVALID_HANDLE_VALUE Then

'This is where the method obtains the file
'list and data for the folder passed.
Call GetFileInformation(FP)

Do

'if the returned item is a folder...
If (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then

'..and the Recurse flag was specified
If FP.bRecurse Then

'remove trailing nulls
sTmp = TrimNull(WFD.cFileName)

'and if the folder is not the default
'self and parent folders...
If sTmp <> "." And sTmp <> ".." Then

'..then the item is a real folder, which
'may contain other sub folders, so assign
'the new folder name to FP.sFileRoot and
'recursively call this function again with
'the amended information.
FP.sFileRoot = sRoot & sTmp
Call SearchForFiles(FP)

End If

End If

End If

'continue looping until FindNextFile returns
'0 (no more matches)
Loop While FindNextFile(hFile, WFD)

'close the find handle
hFile = FindClose(hFile)

End If

End Function

Public Function TrimNull(startstr As String) As String

'returns the string up to the first
'null, if present, or the passed string
Dim pos As Integer

pos = InStr(startstr, Chr\$(0))

If pos Then
TrimNull = Left\$(startstr, pos - 1)
Exit Function
End If

TrimNull = startstr

End Function

Private Function GetFileInformation(FP As FILE_PARAMS) As Long

'local working variables
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
Dim pos As Long
Dim sPath As String
Dim sRoot As String
Dim sTmp As String
Dim sURL As String
Dim sShortcut As String
Dim itmX As ListItem

'FP.sFileRoot (assigned to sRoot) contains
'the path to search.
'
'FP.sFileNameExt (assigned to sPath) contains
'the full path and filespec.
sRoot = QualifyPath(FP.sFileRoot)
sPath = sRoot & FP.sFileNameExt

'obtain handle to the first filespec match
hFile = FindFirstFile(sPath, WFD)

'if valid ...
If hFile <> INVALID_HANDLE_VALUE Then

Do

'remove trailing nulls
sTmp = TrimNull(WFD.cFileName)

'Even though this routine uses filespecs,
'*.* is still valid and will cause the search
'to return folders as well as files, so a
'check against folders is still required.
If Not (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) _
= FILE_ATTRIBUTE_DIRECTORY Then

'determine the link name by removing
'the .url extension
pos = InStr(sTmp, ".url")

If pos > 0 Then

sShortcut = Left\$(sTmp, pos - 1)

'extract the URL
sURL = ProfileGetItem("InternetShortcut", "URL", "", sRoot & sTmp)

Set itmX = ListView1.ListItems.Add(, , sShortcut)
itmX.SubItems(1) = sURL

End If

End If

Loop While FindNextFile(hFile, WFD)

'close the handle
hFile = FindClose(hFile)

End If

End Function

Private Function QualifyPath(sPath As String) As String

'assures that a passed path ends in a slash
If Right\$(sPath, 1) <> "" Then
QualifyPath = sPath & ""
Else: QualifyPath = sPath
End If

End Function

Private Sub Command1_Click()

Dim FP As FILE_PARAMS
Dim favPath As String

'retrieve the special folder path
'to the internet Favourites
favPath = GetFolderPath(CSIDL_FAVORITES)

If Len(favPath) > 0 Then

'set up the search UDT
With FP
.sFileRoot = favPath
.sFileNameExt = "*.url"
.bRecurse = True
End With

'get the files
Call SearchForFiles(FP)

End If

End Sub

Private Function GetFolderPath(CSIDL As Long) As String

Dim sPath As String
Dim sTmp As String

'fill pidl with the specified folder item
sPath = Space\$(MAX_LENGTH)

If SHGetFolderPath(Me.hWnd, CSIDL, 0&, SHGFP_TYPE_CURRENT, sPath) = S_OK Then
sTmp = Left\$(sPath, InStr(sPath, Chr\$(0)) - 1)
End If

GetFolderPath = sTmp

End Function

Public Function ProfileGetItem(lpSectionName As String, _
lpKeyName As String, _
defaultValue As String, _
inifile As String) As String

'Retrieves a value from an ini file corresponding
'to the section and key name passed.
Dim success As Long
Dim nSize As Long
Dim ret As String

'call the API with the parameters passed.
'The return value is the length of the string
'in ret, including the terminating null. If a
'default value was passed, and the section or
'key name are not in the file, that value is
'returned. If no default value was passed (""),

'Pad a string large enough to hold the data.
ret = Space\$(2048)
nSize = Len(ret)
success = GetPrivateProfileString(lpSectionName, lpKeyName, _
defaultValue, ret, nSize, inifile)

If success Then
ProfileGetItem = Left\$(ret, success)
End If

End Function
'--end block--'

Private Sub CancelButton_Click()
End Sub

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)

Combo2.Text = Item.SubItems(1)

End Sub

Compiling To P-code Works, To Native Code Fails
Curious if anyone can tell me what i'm doing wrong here. The code snippet below is the wndproc I subclass my form with. Everything works like a charm when I build to p-code, however when I build to native code, the program exits immediately, just a quick flicker of it starting up and then its gone. I narrowed things down to the "BeginPaint" call. Once I comment it out, native code works again. If anyone can see anything glaring that i'm doing wrong, please let me know...

public Function WndProc(byval hwnd as Long, byval Msg as Long, byval wp as Long, byval lp as Long) as Long
'Initialize a paint structure.
Dim ps as PAINTSTRUCT

'Based on incoming msg, navigate to appropriate handler.
Select Case (Msg)
Case WM_SETTEXT 'Text for Window must be set.
'set buffer.
szCaption = Space\$((len(lp)))

'get Window text.
Call lstrcpy(szCaption, lp)

'Add rectangle to our Window's update region.
Call InvalidateRect(hwnd, 0, true)

Case WM_SETFONT 'Font for Window text must be set.
'get handle of font.
hfnt = wp

Case WM_ERASEBKGND 'Window background must be erased.
'Tell Windows we handled it.
WndProc = 1
Exit Function

Case WM_PAINT 'Window must be painted.
'Prepare Window for painting and fill a Paint Structure.
Call BeginPaint(hwnd, ps)

'Call PaintWnd(hwnd, ps)

'Mark the end of our paint operation.
Call EndPaint(hwnd, ps)

Case else
'Handled below for all other cases.
End Select

'Return msg to Windows for processing.
WndProc = CallWindowProc(OldWindowProc, hwnd, Msg, wp, lp)
End Function

Difference Of Behaviour Between P-code & Native Code Compilations
Hi,

I am facing a funny problem: My app behaves differenty when compiled as p-code and Native code. I was doing p-code compilation to test between IDE (debug) run and release run, because it is fast.

And when i test between p- & n- compiled codes:
The native code compiled program, hangs under certain circumstances, when are handled very well by p-code compiled program. Also under the same circumstanced (which cause the native code program to hang), the debug-run (from the IDE) also, runs with out any problems

Can anyone explain to me what is happening?

Please mail me if you want more info on this, and i will be very happy, if some one is interested in this problem too!!

Also, why does my program run on 4-threads?
I noticed this when i use Process-Viewer of Vc++.
All i am using in my program are a few forms?!?!

Ravi Kiran

Converting C++ Code To Visual Basic Code
I was wondering if anything could go wrong regarding type-conversions between VB and C++ types. Say if I converted a Float to a single, would that lead to enormous flaws??

I'm asking this as I tried converting a physics demo to Visual Basic, but when testing it, it turns out to be, well... highly irratic and inpredictable... I've checked and double checked my code many times, read up on the physics, used debug.print sevearly to no avail...

anyone who had issues like mine, please share, because else I'm forced to making a physics engine myself from scratch (which I reeeeaaaly don't want to do... too lazy & too dumb... no kidding, I would, but rather not...)

thx,
Mathijsken

How Do I Get Code Line Numbers In VB6 Code View?
Hi how do I get numbers at the side of my code in VB6??

Am using Dreamweaver Mx and I have numbers at the side on that. It really helps.

eg,

1 <html>
4<body>
5</body>
6</html>

I want to display numbers against my code lines like that. Can this be done in VB6. And if so how please.

Thanks

VB Code COntrol..Text To VB Code Color?????
I am looking for a control I found a year aso ago. I am needing this or something like it.

I have writen a CodeLibrary and I am looking for a text control that will turn VB code text into what it looks like in the vb editor.

Does anyone know of this control or one like it?

vbMarkO

Meaning Of # In [code]a = 10000# * Year[/code]
Hi!

I'm trying to adapt some code to another language and I'm not sure of the meaning of # in this:

Code:
Function X(year As Integer, month As Integer, day As Integer, ...) as Double

Dim a As Double

a = 10000# * year + 100# * month + day
X = a
Calculated by hand without caring about # gives the same result but deleting # in the function gives a #Value! error...

Thanks!

Changing VB Access Code To VB SQL Server Code
Hello guys...

I need some serious help with this code. Somebody else wrote the code for the database in access. But now I have transfered the tables to SQL Server and have created a new VB Form.

THE VB CODE IN MS Access is as follows. What do I need to do to it for it to work with the SQL Server using the VB Form. Its a code for one click button.

Private Sub CmdImport_Click()
Dim db As Database
Dim rs As DAO.RecordSet
Dim SQL As String
Dim objxlapp As Excel.Application
Dim fs
Dim myDir As String
Dim myFile As String
Set fs = CreateObject("Scripting.FileSystemObject")

Set db = CurrentDb
If CheckRates = False Then
'CheckFilestoUpdate
SQL = "Select * From tblDBImportStructure where Use = 1"
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)

With rs
.MoveFirst
Do Until .EOF
sPath = LocateFile(.Fields("Title"), .Fields("Type"), .Fields("DefaultPath"))
If sPath <> "False" Then
fs.CopyFile sPath, .Fields("FileDir") & Format(Form_frmMain.txtasofdate, "mmddyy") & ".xls"
sPath = .Fields("FileDir") & Format(Form_frmMain.txtasofdate, "mmddyy") & ".xls"
.Edit
.Fields("FilePath") = sPath
.Update
Else:
MsgBox "You cancled the previous operation"
Exit Sub
End If
.MoveNext
Loop
.Close
End With

'***Update Version Of Excel***
Set objxlapp = New Excel.Application
objxlapp.Workbooks.Open (sPath)
objxlapp.ActiveWorkbook.SaveAs (sPath), xlNormal
objxlapp.ActiveWorkbook.Close
objxlapp.Quit
Set objxlapp = Nothing

db.Execute "Delete * From tblFailsData"

GetTableInfo
UpdateRates
Beep
MsgBox "Finshed with import."
Exit Sub
End If
MsgBox "Your have not updated the As Of Date, Interest Rate or Spot Rate, Please do so."
End Sub

Multimedia Timer (P-Code Vs. Native Code)
What would be the difference in the way a P-code exectuble performs
to that of a Native code exe?

My Multimedia Timer executes when compiled to P-code, but crashes
when compiled to the other.

P-Code / Native Code Compile Question.
I've come across a problem where my app freezes if i use a Native compile, although it works totally fine when ran in VB. Now if i switch over to a P-Code compile it works 100% when compiled.

Correct me if i'm wrong, but the Native compile adds the dll code in with the exe. So since i'm forced to run a P-Code compile, what files will i need to include with my app in order for it to run? Also is their any downfalls other than including .dll files with the app, such as security issues while using P-Code?

Thanks a bunch!

Porting DAO VB6 Code To ODBC/server Code
Hi all.

I'm guessing the answer to the following question is a no but I'm asking for confirmation more than anything.

I am trying to port a VB6 project based on an Access 97 platform to one which accesses the same database structure on an SQL Server. Has Microsoft developed any tools where you can give the VB project or module and it runs through it changing the relevant calls etc? If you can recommend any references that would be great.

TIA

How To Code (chain Code 8 Connectivity Algorithm) In Vb6
Can any one help me with the chain code algorithm implementation. i need to know if this algorithm can be implemented in vb 6 or not

Opinions: Clean Code And Fast Code
First off, does anyone have a link to a guide for writing cleaner code. I find that if I read it somewhere I am more likley to do it than just making up guidelines myself. That's why I like XHTML, the rules are strict and everything comes out very clean.

Anyway, I have most of programs call a function/sub that I define when an event occurs (instead of writing the code directly into the event).

Heres the question: Do you guys think it is cleaner to pass most values via the sub's arguments or to simply use the values in the sub? Also, is it faster/more efficient to do it this way?

Obviously the argument option is better if you call the sub in multiple different ways.

What do you think?

Difference Between Native Code And P-Code Compilation
hi,
i want to know abt difference between Native Code and p-Code Compilation.
help me
manesh

------------------------------------------------------------------------------------
if Proper(Code)=False then
msgbox "www.VbForums.Com"
else
msgbox "Great Manesh"
endif

How Can I Use This Code Or Any Code To Get The Full Path Including The Name?
im usin the below code to get the path for the file that is draged over a listbox.

VB Code:
Public Function GetPath(ByVal sFile As String, Optional ByVal Slash = False) As String    'True shows "" at the end    'False doesn't    GetPath = IIf(Slash = False, Left\$(sFile, InStrRev(sFile, "") - 1), Left\$(sFile, InStrRev(sFile, "")))End Function

so when i use it i get C:WINDOWSDesktop
but i wana get the full path. i.e. C:WINDOWSDesktopfilename.txt

how could i do this?