|
You would be better off storing your list in an external file or database, rather than hard-coding them into your program code. That way, if the list changes, you simply need to update the (external) data rather than having to modify your application.
|
|
|
|
|
Thanks that has given me some good ideas now
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Modules aren't really that OOP so I tend to stay away from them. A nice way may be to create a class called InsuranceItems which inherits List<insuranceitem> and then create a function within the inherited class which returns a list of advisories.
Public Class InsuranceItems
Inherits List(Of InsuranceItem)
Public Function GetAdvisories() As List(Of Advisory)
'Do stuff and return list
End Function
End Class
"You get that on the big jobs."
|
|
|
|
|
Thanks that has given me good things to go on
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
I have googled, but would prefer advice or suggestions...
I want to just have a way of copying a folder ( and contents ) to a memory stick at the click of a mouse.
There is a manager who wants this made easy.
I am thinking For each Element in Files kind of thing.
But is there an easier way?
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Dalek Dave wrote: is there an easier way?
There are plenty:
- Synchronization tools.
- Backup tools.
- Rentacoder.
...
and in the end they all use at least one loop and possibly some recursion.
just-a-link[^]
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks for all your help there Luc!
Invaluable.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
|
Try this link:
http://www.codeproject.com/Messages/3526402/Re-Is-it-the-right-approach-to-speed-up-the-copy-p.aspx[^]
Or try this code:
Public Class FileSearch
Inherits System.Collections.Generic.List(Of String)
#Region "-----------------------------------------------------Events"
Public Event NewFileList(ByVal Sender As Object, ByVal e As FSrcEventArgs)
Public Event CurrentFolder(ByVal Sender As Object, ByVal e As FSrcEventArgs)
Public Event CurrentEvent(ByVal Sender As Object, ByVal e As FSrcEventArgs)
#End Region
#Region "--------------------------------------------Public Variables"
Public AddOnObj As Object, Info As String = "", FolderCount As Long, StopSearching As Boolean, FolderList As New List(Of String)
Public Shared ExcludeFolder As String = "Unwanted Programs", ExcludeSignFile As String = "\info.inf", ExcludeSign As String = "simpledata"
#End Region
#Region "-------------------------------------------Local Variables"
Dim e As New FSrcEventArgs
Private G_FileTypes() As String
Private Parent As System.Windows.Forms.Control
#End Region
Sub Reset()
e = New FSrcEventArgs
Me.Clear()
StopSearching = False
G_FileTypes = Nothing
FolderCount = 0
AddOnObj = Nothing
Info = ""
End Sub
#Region "--------------------------------------------FSrcEventArgs Class"
Public Class FSrcEventArgs
Inherits System.EventArgs
Friend Enum EventTypes
None = 0
Dirs = 1
Files = 2
Informations = 3
End Enum
Public Directory As String = ""
Public CurrentList As New List(Of String)
Public Completed As Boolean = False
Public StopSearching As Boolean = False
Public FileCount As Integer = 0
Public DirCount As Integer = 0
Public Info As String = ""
Public Exclude_This_Folder As Boolean
Friend EventType As EventTypes = EventTypes.None
Friend Sub CopyArgs(ByVal Directory As String, _
ByVal CurrentList As List(Of String), _
ByVal Completed As Boolean, _
ByVal StopSearching As Boolean, _
ByVal FileCount As Integer, _
ByVal DirCount As Integer, _
ByVal Info As String, _
ByVal EventType As EventTypes, ByVal Exclude_This_Folder As String)
With Me
.Directory = Directory
.CurrentList = CurrentList
.Completed = Completed
.StopSearching = StopSearching
.FileCount = FileCount
.DirCount = DirCount
.Info = Info
.EventType = EventType
End With
End Sub
End Class
#End Region
Sub GetAllFiles(ByVal InFolder As String, Optional ByVal FileTypes As String = "*.*", Optional ByVal contains As String = "")
e.Directory = InFolder
FolderList.Add(InFolder)
e.CopyArgs(InFolder, Me, e.Completed, StopSearching, Me.Count, FolderCount, "Searching Completed", FSrcEventArgs.EventTypes.Dirs, False)
Dim DG As New DLG_SrcInfo_all(AddressOf SUB_SrcInfo_all)
Try
Me.Parent.Invoke(DG, Me, e)
Catch ex As Exception
End Try
FindInFolder(InFolder, FileTypes, contains)
e.Completed = True
e.CopyArgs(InFolder, Me, e.Completed, StopSearching, Me.Count, FolderCount, "Searching Completed. Total Files: " & Me.Count, FSrcEventArgs.EventTypes.Informations, False)
Try
Me.Parent.Invoke(DG, Me, e)
Catch ex As Exception
End Try
End Sub
Shadows Function ToString(ByVal Delimiter As String) As String
Me.ToArray()
Return Microsoft.VisualBasic.Strings.Join(Me.ToArray, Delimiter)
End Function
Function FindInFolder(ByVal InFolder As String, Optional ByVal FileTypes As String = "*.*", Optional ByVal contains As String = "") As System.Collections.Generic.IEnumerable(Of String)
Dim xx = InFolder
If IsNothing(G_FileTypes) Then
G_FileTypes = FileTypes.Split(New [Char]() {","c})
End If
Try
Dim ps As Integer = InStr(InFolder, ExcludeFolder, CompareMethod.Text)
If ps > 0 Then
Dim FD As String = My.Computer.FileSystem.ReadAllText(InFolder & ExcludeSignFile)
If FD.Length = ExcludeSign.Length Then
Return Me
End If
End If
Catch ex As Exception
End Try
Dim DG As New DLG_SrcInfo_all(AddressOf SUB_SrcInfo_all)
Try
Me.AddRange(FindFiles(InFolder, FileTypes, contains))
Catch ex As Exception
Return Me
End Try
FolderCount += 1
e.CopyArgs(InFolder, e.CurrentList, e.Completed, StopSearching, Me.Count, FolderCount, "Searching for folders in '" & InFolder & "'", FSrcEventArgs.EventTypes.Informations, False)
Try
Me.Parent.Invoke(DG, Me, e)
Catch ex As Exception
End Try
For Each Directory As String In My.Computer.FileSystem.GetDirectories(InFolder, FileIO.SearchOption.SearchTopLevelOnly)
If StopSearching Then
e.CopyArgs(Directory, e.CurrentList, e.Completed, StopSearching, Me.Count, FolderCount, "Searching Stopped", FSrcEventArgs.EventTypes.Informations, False)
If Not IsNothing(Parent) Then
Me.Parent.Invoke(DG, Me, e)
End If
Return Nothing
End If
e.CopyArgs(Directory, e.CurrentList, e.Completed, StopSearching, Me.Count, FolderCount, "Searching for folders in '" & InFolder & "'", FSrcEventArgs.EventTypes.Dirs, False)
If Not IsNothing(Parent) Then
If Parent.Disposing Then
Else
Me.Parent.Invoke(DG, Me, e)
End If
End If
If e.Exclude_This_Folder Then
e.Exclude_This_Folder = False
Continue For
Else
FolderList.Add(Directory)
End If
Try
FindInFolder(Directory, FileTypes, contains)
Catch ex As Exception
xx = ex.ToString()
Continue For
End Try
Next
Return Me
End Function
#Region " -------------------------------------------- Delegates"
Private Delegate Sub DLG_SrcInfo_all(ByVal Sender As Object, ByVal e As FSrcEventArgs)
Private Sub SUB_SrcInfo_all(ByVal Sender As Object, ByVal e As FSrcEventArgs)
If StopSearching = True Then
Return
End If
Select Case e.EventType
Case FSrcEventArgs.EventTypes.Dirs
RaiseEvent CurrentFolder(Sender, e)
Case FSrcEventArgs.EventTypes.Files
RaiseEvent NewFileList(Sender, e)
Case FSrcEventArgs.EventTypes.Informations
RaiseEvent CurrentEvent(Sender, e)
End Select
End Sub
#End Region
Function FindFiles(ByVal InFolder As String, Optional ByVal FileTypes As String = "*.*", Optional ByVal contains As String = "") As System.Collections.Generic.IEnumerable(Of String)
On Error GoTo Errr
If StopSearching Then
Return Nothing
End If
Dim la As ArrayList
If IsNothing(G_FileTypes) Then
G_FileTypes = FileTypes.Split(New [Char]() {","c})
End If
Dim lResult As New List(Of String)
Dim DG As New DLG_SrcInfo_all(AddressOf SUB_SrcInfo_all)
e.CopyArgs(InFolder, e.CurrentList, e.Completed, StopSearching, Me.Count, FolderCount, "Searching for files in '" & InFolder & "'", FSrcEventArgs.EventTypes.Informations, False)
On Error Resume Next
Me.Parent.Invoke(DG, Me, e)
On Error GoTo Errr
lResult.AddRange(My.Computer.FileSystem.FindInFiles(InFolder, _
contains, False, FileIO.SearchOption.SearchTopLevelOnly, _
G_FileTypes))
If lResult.Count > 0 Then
e.CurrentList = lResult
e.CopyArgs(InFolder, lResult, e.Completed, StopSearching, Me.Count, FolderCount, "Search Completed at folder '" & InFolder & "'", FSrcEventArgs.EventTypes.Files, False)
On Error Resume Next
Me.Parent.Invoke(DG, Me, e)
On Error GoTo Errr
End If
If IsNothing(AddOnObj) Then
Else
AddOnObj.AddRange(lResult.ToArray)
End If
Return lResult
Errr:
Return Nothing
End Function
Public Sub New()
End Sub
Public Sub New(ByVal Parent As System.Windows.Forms.Control)
Me.Parent = Parent
End Sub
End Class
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++****************
I’ll be pleased if you give me any bugs report & fix that.
Here is a sample form to call that.(bugs report are not needed for below code because I know that. Its a testing.)
Public Class Form1
Dim WithEvents FF As New System_Tools.Task_Explorer
Dim WithEvents CC As System_Tools.HOOK_
Dim di As New System_Tools.HOOK_
Dim WithEvents FS As System_Tools.FileSearch
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
BackgroundWorker1.RunWorkerAsync(Me.ComboBox1.Text)
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
FS = New System_Tools.FileSearch(Me)
Dim xx As List(Of String)
FS.GetAllFiles(e.Argument.ToString)
End Sub
Private Sub FS_CurrentEvent(ByVal Sender As Object, ByVal e As System_Tools.FileSearch.FSrcEventArgs) Handles FS.CurrentEvent
Dim xx
Me.Text = e.Info
If e.Completed Then
Beep()
xx = EvList
xx = RefList
Me.Text = e.Info & " " & Sender.count
End If
End Sub
Private Sub FS_CurrentFolder(ByVal Sender As Object, ByVal e As System_Tools.FileSearch.FSrcEventArgs) Handles FS.CurrentFolder
Dim xx
Me.Text = e.Info
If e.Completed Then
Beep()
xx = EvList
xx = RefList
End If
End Sub
Private Sub FS_NewFileList(ByVal Sender As Object, ByVal e As System_Tools.FileSearch.FSrcEventArgs) Handles FS.NewFileList
EvList.AddRange(e.CurrentList)
Dim xx
Me.Text = e.Info
If e.Completed Then
Beep()
xx = EvList
xx = RefList
End If
TextBox1.Text = Join(e.CurrentList.ToArray, vbNewLine)
End Sub
Dim EvList, RefList As New List(Of String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("C:\")
ComboBox1.Items.Add("d:\")
ComboBox1.Items.Add("e:\")
ComboBox1.Items.Add("f:\")
ComboBox1.Items.Add("g:\")
ComboBox1.Items.Add("h:\")
ComboBox1.Items.Add("i:\")
ComboBox1.Items.Add("j:\")
ComboBox1.Items.Add("k:\")
ComboBox1.Text = "C:\"
Debug.WriteLine("Leaving ExpTree ShDragDrop")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xx
CC.autocheck1time()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim xx
End Sub
Private Sub FF_Task_Explorer_Terminated() Handles FF.Task_Explorer_Terminated
FF.Dispose()
End Sub
Private Sub CC_
Dim addrem As String = ""
If e.
addrem = "Added: " & e.DriveInfo.Name & "-" & e.DriveInfo.VolumeLabel & vbNewLine
ElseIf e.
addrem = "Removed: " & e.DriveInfo.Name & vbNewLine
End If
Me.Text = e.
TextBox1.AppendText(addrem)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Text = System_Tools.FileAccess.FileLenStr("H:\PLangs.iso")
End Sub
End Class
Oh, I forgot to say that sample form could raise errors because some classes are not given. Just remove which raise error.
______________
Aslam Iqbal
|
|
|
|
|
Hi,
I am Using Slider control. I want Small changes value set in floating point. It is possible? I have move to slider control on 0.1, 0.2, 0.3..... to 1.
Pls help any idea? or url pls
Regards,
M.Mathivanan
|
|
|
|
|
This[^] CP Archive item may help.
But your question is somewhat ambiguous.
You want an actual value changed?
Or you want the figures shown to change?
Unclear, please post the code you have so far.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
I think one of the change properties will do what you need; see here[^] for more information.
I must get a clever new signature for 2011.
|
|
|
|
|
Or is your problem number management, the slider only deals with integers (I have not checked). If so the multiply the 0.1 by 10 between your data and the slider control.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: the slider only deals with integers (I have not checked)
I did check, and it supports changing by double .
I must get a clever new signature for 2011.
|
|
|
|
|
Yeah it did sound a lot simplistic but I'be heard of sillier issues.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi there,
I'm sorry to bug, but I have been searching today for something like the code I did (see bellow) and I couldn't really find anything alike so I took some ideas and added some lines and so far it worked on a test folder (drilling down through sub-folders and different ext, etc)
What I need is some guidance and just for you to take a look at the code and let me know if there is a way to improve it and/or bullet proof it. I do have more than 25k files to update and I don't want to do it later on manually!
The information to be updated are movie files The Folder has a name (Sample: SQL.Proyect.20100525) But the movie was named just "Movie", and I need to update that. The path looks like (Z:\20\1\0\SQL.Proyect.20100525\Movie.avi)
One more thing: Keep in mind that I just learned today .vbs
So your expertise will be much appreciate it!
<br />
Option Explicit<br />
Dim objFSO, strDIR, objDIR<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
strDIR = "C:\vbScript"<br />
Set objDIR = objFSO.GetFolder(strDIR)<br />
RenameVideos(objDIR)<br />
Sub RenameVideos(curPath)<br />
Dim vItem, vCurName, vCurPath, vNewName, vNewPath, vShwName<br />
For Each vItem In curPath.Files<br />
If objFSO.GetBaseName(vItem.Path) = "Movie" Then<br />
vCurName = objFSO.GetFileName(vItem.Path)<br />
vCurPath = objFSO.GetParentFolderName(vItem.Path) & "\" & objFSO.GetFileName(vItem.Path)<br />
vShwName = objFSO.GetParentFolderName(vItem.Path)<br />
vNewName = objFSO.GetBaseName(vShwName) & "." & objFSO.GetExtensionName(vCurName)<br />
vNewPath = objFSO.GetParentFolderName(vItem.Path) & "\" & objFSO.GetFileName(vNewName)<br />
Wscript.Echo "The File Name: " & vCurName & chr(13) & _<br />
"Location Path: " & vCurPath & chr(13) & _<br />
"Will be renamed to: " & vNewName & chr(13) & _<br />
"New Unique Path: " & vNewPath<br />
objFSO.MoveFile vCurPath, vNewPath <br />
End If<br />
Next<br />
For Each vItem In curPath.SubFolders<br />
RenameVideos(vItem)<br />
Next<br />
End Sub<br />
|
|
|
|
|
Well, i wouldn't bother using vbscript.
I would write a small app to do this in VB.net.
If you don't have Visual Studio, you could always download the express editions for free from MS.
It will be more reliable, easier to debug and maintain. oh, and you can always give it a nice gui to look at if you want
|
|
|
|
|
Hi,
I need a guidance on how to achieve this global search in vb.net using sql express.
cenario:
I have a Mdi parent form as main window.
I add a toolstrip so I can add a label, textbox and a search botton.
I want a global search for serial number, when found, a child form load with its record; if not found, a message.
tables structure:
inventory(inv_ID, serial_no, Type, etc..)
Lost(lost_id, inv_id, date, etc..)
repair(repair_id, inv_id, etc..)
training(tran_id, inv_id,etc..)
wherever the serial number appears on view from these tables, I need the result.
problems:
1)if I do a view for all, I will get no record if one of the fk key is not there...
2)I cannot drop the pk key on the form to do a recursive search.
Please guide me on this.
thank you in advance
|
|
|
|
|
That isn't clear to me. What do you mean by "global search"? what is known, and what is unknown? maybe an example is in order.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi
What I meant by it is a search in general.
If I am on the main window form ,I want to search for a serial number without having to click on any form. That is why I put a search button on the menu.
The inventory table is the main table, when I search I should get the state of serial number whether it is in lost, repair, etc.. And load the form corresponding to its state.
I hope I am clearer now.
Thanks again
|
|
|
|
|
Am I to understand that each of the objects in your database will move from one table to tbe next when it changes state? I don't think that is good design. I'd rather go for one table that holds all objects, with an extra field indicating its state (inventory, lost, repair, whatever). And when more info needs be stored in a state-dependent way, then add that in separate tables.
Doing so, I expect fewer problems and less code.
Furthermore, you may want to keep track of the states an object has been in. That would allow you to answer questions such as: how often has an object been repaired? What is the average time span between repairs for objects needing multiple repairs? etc.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi
Ok. I have armory table (armory_id, inv_id, lost_id, repair_id)
When I do a view on this table, if one of the fk. Key is missing. I get no result, here lies my problem. If I can get this solves, I really would like to tackle on those questions you mentioned
I thank you for your walkthrough on this one.
|
|
|
|
|
I'm still confused. In my world each object would have a unique and constant ID, and all those pretty similar objects would sit in a single table. They could change state, get extra information in other tables, but they would not move out of the primary table, and they would not change their ID. If that is the model you want but not currently have, you would need:
1.
some run-once code to make sure the above invariant holds true; it would look for entries in other tables that are not currently present in the main table.
2.
a thorough check of all code to make sure the invariant is maintained, so objects don't move out of the primary table ever again.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes I am sensing that I need to change my current model but I am bit off line with my table structure.
Main table is armory(armory_id, inv_id, lost_id,repair_id)
Would it be instead (armor_id, inv_id, lostcheckbox, repaircheckbox)
That would give me the state of a particular serail no)
Then I can load its record from the current state.
Thanks
|
|
|
|
|
I don't know what information you want to store, and what search operations you are going to need, so I can only gamble a bit. Maybe this:
armory(armory_id, current_state, armory_description)
actions(action_id, armory_id, action_start, action_end, action_description)
Note there are no links from armory to actions!
and current_state would be an enum with possible values: normal, lost, in repair, ...
one could argue current_state is redundant, it should always match the outcome of the last action.
both tables would only be allowed to grow, and probably actions with same armory_id should not overlap time wise.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|