|
I am still quite new and this project is a second attempt, the first time was five years ago, this time it is working much better with VB Studio, thanks for the help, I will give it a try.
When this project is completely debugged I will then give proper names and re-debug.
Training in progress.....
Duane in Japan
|
|
|
|
|
Hi all,
I have a big folder its size is 3G I like to split it to multiple folders.Everyone has a suggestion please give me. Thanks
|
|
|
|
|
What does this have to do with VB.NET?? Why split the folder into multiple folders? What's the point?
|
|
|
|
|
Dave Kreskowiak wrote: What does this have to do with VB.NET?
Exactly. Unless he wants to write some app that splits large folders down to smaller folders?
|
|
|
|
|
My folder is big including over 40000 files and everytime it is opened and taken time on that. I like to divide it to mulitple folders and each folers has around 1000 files from the big folders depends on the size of each file.
I like to set for each folder has a limit size 100M.
Thanks for response my question.
-- modified at 11:57 Friday 1st June, 2007
|
|
|
|
|
That ain't big. When you get to 2 million files in 350,000 folders, call me. THAT'S big! (and utterly ridiculous too!)
So what is this reorganization going to do to the applications that use these files?
I'd probably start with the Driectory class and it's GetFiles method to get an array of filenames. Create a folder, then enumerating the list of files. Use the FileInfo class to get the size of the file, then move the file into the new folder, keeping track of the total size of the files you moved into that folder. When the size reaches your limit, create a new folder, reset the counter, and resume moving files into the new folder.
|
|
|
|
|
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folBrowse As New FolderBrowserDialog
folBrowse.ShowDialog()
Dim dirInfo As New System.IO.DirectoryInfo(folBrowse.SelectedPath)
Dim index As Integer = 0
Do Until dirInfo.GetFiles.Length = 0
sortFolder(folBrowse.SelectedPath, "newfolder" & index)
index = index + 1
Loop
MsgBox("Completely done")
End Sub
Private Sub sortFolder(ByVal selFolder As String, ByVal newFolName As String)
On Error Resume Next
'set the selected folder
Dim selPath As String = selFolder
'set the size variable to calculate the total size of the new folder
Dim newSize As Integer = 0
'get the directory info for the selected folder
Dim dInfo As New System.IO.DirectoryInfo(selPath)
'iterate through the the first thousand files in the selected folder
For i As Integer = 0 To 2
'if we reach the end of the list, exit the for loop
If i >= dInfo.GetFiles.Length Then Exit For
'set the folder name (you can change to whatever you want)
Dim folderName As String = newFolName
'set the new folder path
Dim curFolder As String = selPath & "\" & folderName
'make the new folder
MkDir(curFolder)
'if we reach the end of the list then we exit
If i >= dInfo.GetFiles.Length Then Exit For
'set the current file
Dim curFile As String = dInfo.GetFiles.GetValue(i).ToString
'copy the file to the new folder
FileCopy(selPath & "\" & curFile, curFolder & "\" & curFile)
'delete the old file
Kill(selPath & "\" & curFile)
'set the new folder directory info and size to zero
Dim newFolderInfo As New System.IO.DirectoryInfo(curFolder)
newSize = 0
'iterate through the files in the new folder and adds the size of each
For n As Integer = 0 To newFolderInfo.GetFiles.Length - 1
newSize += FileLen(curFolder & "\" & newFolderInfo.GetFiles.GetValue(n).ToString)
Next
'if the new folder's size is greater than or equal to 100MB we exit the loop
If newSize >= 104857600 Then
Exit For
End If
Next
End Sub
End Class
---------------
I put 4 files in the folder
I have the problem that it makes more folders and the first folder will be hold 2, the second folder will be hold 1 file and the third one will be hold 1 file.
Could you please show me what is my problem? Thanks.
|
|
|
|
|
I really can't point out where it went wrong because it has as many problems as there are lines of code. The only suggestion I have to is to scrap it and start over. Think about the problem and the steps needed to solve it.
You're using old-style VB6 error handing and file/directory functions. Don't. Use Try/Catch blocks and the classes under the System.Io namespace. I think this can be done in under 20 lines of code using a few tracking variables and the Directory and FileInfo classes.
I'll give yo ua hint. I'd start with this:
Private Sub DivideFolder(ByVal sourceRootFolder As String, ByVal destinationRootFolder As String, ByVal destinationFolderName As String, ByVal maxFolderSize As Long)
|
|
|
|
|
OK, so I've created an .exe file with its dependencies. My user downloads all of the files
in their folders, but immediately gets a windows error when he runs the .exe. Some .dll is probably missing
somewhere. How can I help him debug what the problem is? The problem is occurring on startup, before we
even get to my first line of code.
thank you.
|
|
|
|
|
Sounds like he doesn't have the .NET framework installed.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
No, I don't think so. I believe that if you try to run a vb.net application without .net installed you get a specific error about that.
In any case, I can create the same type problem on my own machine -- just remove one of the .dlls that the .exe needs, and
you get a Windows form... "XXX has encountered a problem and needs to close....."... but with no message about what is wrong.
WOuld a debug build and a deployment build work differently in this regard?
Thanks
|
|
|
|
|
cstrader232 wrote: In any case, I can create the same type problem on my own machine -- just remove one of the .dlls that the .exe needs, and
you get a Windows form... "XXX has encountered a problem and needs to close....."... but with no message about what is wrong.
OK - well, either they are missing a dll or they don't have the framework. It's obviously a dependancy issue, if the code never even runs.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'll second what Christian said. Either he doesn't have the .NET Framework installed at all, or he needs 2.0 and only has a 1.x version installed.
|
|
|
|
|
OK, this is completely frustrating to me. I've developed this nice .net project but cannot deploy it.
The user definitely has net 2.0 installed.
When I look at the manifest, all of the dependicies listed there are available in the startup directory.
How can I find what is missing? The windows error says nothing at all about the problem.
Can I attach a debugger or something?
thanks
|
|
|
|
|
To start troubleshooting assembly load failures, start here[^].
|
|
|
|
|
How can use virus scan in my appliction, such as norton or macafee that are already installed on our system.
Thank you!
"Mess with the Best, Die like the rest"
|
|
|
|
|
Contact the manufacturer of the virus scan you're using and see if they have an SDK for it.
|
|
|
|
|
Hello All,
Iam trying to create a Windows service. I created a class library which has a few methods which access a database and return data and the service. So in my solution i have 2 projects
1.Class Library called -EventLibrary(all methods here are remotable)
2.InstallerService- which will install this service.
The service is installed and running.
My problem is this.The methods in EventLibrary need to access a database. I tried adding a app config file to the Class library project and added the db connection parameters. But when my client application runs, VS 2005 tries to look for the config item from the client app.config.Since its a 3 tier architecture I dont want to put any config items on the client side.
How do i make the service look for the db config item from the config file in Class Library???
Help and Sample code are much appreciated.
Thanks in advance
RH
|
|
|
|
|
The app.config file need to be where the service is compiled. It gets renamed to the servicename.exe.config. So that is where it is looking for the config settings. So if you move the app.config file out of the class and into the service project it should work just fine.
Ben
|
|
|
|
|
Hi,
I want to display the image in Picture Box in VB 6.0. I have the output in ByteArray. How can I display the image in picturebox?
Thanks in advance,
AR Reddy
|
|
|
|
|
A quick Google for "VB6 convert byte array to bitmap" came up with this[^].
|
|
|
|
|
Example like this:
Create a form within a PictureBox control.
Type the code:
Dim arrayPic() As Byte<br />
Open "testpic.jpg" For Binary As #1<br />
ReDim arrayPic(LOF(1))<br />
Get #1, , arrayPic<br />
Close #1<br />
Picture1.Picture = PictureFromBits(a)
Create a module and type the code:
Public Enum CBoolean<br />
CFalse = 0<br />
CTrue = 1<br />
End Enum<br />
<br />
Public Const S_OK = 0<br />
<br />
Declare Function CreateStreamOnHGlobal Lib "ole32" _<br />
(ByVal hGlobal As Long, _<br />
ByVal fDeleteOnRelease As CBoolean, _<br />
ppstm As Any) As Long<br />
<br />
Declare Function OleLoadPicture Lib "olepro32" _<br />
(pStream As Any, _<br />
ByVal lSize As Long, _<br />
ByVal fRunmode As CBoolean, _<br />
riid As GUID, _<br />
ppvObj As Any) As Long<br />
<br />
Public Type GUID<br />
dwData1 As Long<br />
wData2 As Integer<br />
wData3 As Integer<br />
abData4(7) As Byte<br />
End Type<br />
<br />
Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As GUID) As Long<br />
<br />
Public Const sIID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"<br />
<br />
Public Const GMEM_MOVEABLE = &H2<br />
Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long<br />
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long<br />
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long<br />
<br />
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)<br />
<br />
<br />
Public Function PictureFromBits(abPic() As Byte) As IPicture<br />
Dim nLow As Long<br />
Dim cbMem As Long<br />
Dim hMem As Long<br />
Dim lpMem As Long<br />
Dim IID_IPicture As GUID<br />
Dim istm As stdole.IUnknown<br />
Dim ipic As IPicture<br />
<br />
On Error GoTo Out<br />
nLow = LBound(abPic)<br />
On Error GoTo 0<br />
cbMem = (UBound(abPic) - nLow) + 1<br />
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)<br />
If hMem Then<br />
lpMem = GlobalLock(hMem)<br />
If lpMem Then<br />
MoveMemory ByVal lpMem, abPic(nLow), cbMem<br />
Call GlobalUnlock(hMem)<br />
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then<br />
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then<br />
Call OleLoadPicture(ByVal ObjPtr(istm), cbMem, CFalse, IID_IPicture, PictureFromBits)<br />
End If<br />
End If<br />
End If<br />
End If<br />
Out:<br />
End Function
Now you can run your application and see the control of PictureBox shown you a picture from ByteArray.
My English is not very well,so I make some mistakes,maybe!
Don't laugh at me,please!
If you still show no picture from ByteArray,you should send me a email to billypon@21cn.com.
Gook Luck!!!
|
|
|
|
|
Hi Billypon,
Thanks a Lot. Your code is working fine and I am able to display the image. Now I have one more problem is:
I have already image loaded into the memory and I have that memory address pointer. How can I convert that into bytes or bytearray, so that I can use your previous code to display into a picture box.
Thanks in advance.
AR Reddy
|
|
|
|
|
Add this API declare to the Module which I told you.
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
And the write down this function into the Module.
Public Function PictureFromPointer(Pointer As Long, Length As Long) As IPicture<br />
Dim hMem As Long<br />
Dim lpMem As Long<br />
Dim IID_IPicture As GUID<br />
Dim istm As stdole.IUnknown<br />
Dim ipic As IPicture<br />
<br />
On Error GoTo Out<br />
If Pointer > 0 And Length > 0 Then<br />
hMem = GlobalAlloc(GMEM_MOVEABLE, Length)<br />
If hMem Then<br />
lpMem = GlobalLock(hMem)<br />
If lpMem Then<br />
CopyMemory ByVal lpMem, Pointer, Length<br />
Call GlobalUnlock(hMem)<br />
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then<br />
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then<br />
Call OleLoadPicture(ByVal ObjPtr(istm), Length, CFalse, IID_IPicture, PictureFromPointer)<br />
End If<br />
End If<br />
End If<br />
End If<br />
End If<br />
Out:<br />
End Function
Now you can use the function like this:
PictureFromPointer(YourPointer,LengthOfPointer)
I was test nothing about this function,so I can't promise it will work fine..
Luckly!!!
-- modified at 22:31 Friday 1st June, 2007
|
|
|
|
|
I am using a DataGrid to retrieve and update data within an Access database. The VB books do a good job in telling me how to use the Insert, Update, and Delete commands for an existing table. However, I would also like to delete an entire table within the Access database and I would like to add a new table according to a DataTable that was created within the VB program. Any suggestions?
Rich Feldman
|
|
|
|