|
Google this: "jagged arrays vb .net"
|
|
|
|
|
So you say that you need to create variables dynamically? Well, that's not possible in VB.NET. Why? Because noone ever needs to do that. Ever.
You say that you need to create an array that has a specific name. Strictly speaking that is not possible either, as an array doesn't even have a name.
When you create an array object you get a reference to the object. That reference is usually assigned to a reference variable. For example:
Dim a As String[] = New String[42];
Here the statement New String[42] creates the actual array, and the value of that statement is the reference to the array. The variable a can hold a reference to an object of the type String[] . The reference to the array is stored in the variable.
You can have any number of references to a specific object. Example:
Dim b As String[] = a;<br />
Dim c As String[] = a;
Now you have three references to the array, but there is still only one array. You have three references with different names, and the array doesn't have a name at all.
---
b { font-weight: normal; }
|
|
|
|
|
OK. Here's what you need to do. Or what I would do.*
I would use a HashTable of ArrayLists. Quick, easy, efficient, fairly robust, good cost/benefit ratio. Downside: Not strongly-typed.
You don't want to use raw arrays because you would either have to oversize them to begin with (how many? 1000? 5000? Wasteful and error prone), OR you would have to keep ReDim'ing them (bad performance). You could use ArrayList to get around that problem, but you still have no good keyed access to your entries.
That's where the HashTable comes in.
The HashTable (or Dictionary<..>, depending on your version and requirements) simply stores entries of Key and Value pairs.
In this case your Key would be the Call Center number, and it's Value would be an ArrayList.
The ArrayList would store the Agent objects.
Every time you hit a new call center, you create a new hashtable entry using the call center number as the key, and a new arraylist with the Agent on that call as it's initial value, which effectively allows you to "create a new variable at runtime with a particular name".
(Or, instead of storing the agent object in the arraylist slot, you could create a hashtable of Agents, and just store a reference to that agent's entry in the arraylist slot.)
How do you know it's a new call center? By using the ContainsKey function of the hashtable, or by simply trying to access the item with that key. If it doesn't exist, you get back Null. If it does exist, you add the agent (or a reference to the agent) to its arraylist. Simple.
If you're not familiar with hashtables, take an hour or so and read up on them. Set one up and play with it. Don't be afraid of them. Very powerful tool.
*Now. All that having been said, this is NOT the only way or best way to engineer this, it's just a quick-and-dirty as far as I look at it.
Keep in mind what Dave K. said. What you're really doing here is modeling and managing entity relationships. Call Centers, Agents, Calls, Extensions...
Which means you might be better served to use a strongly-typed DataSet, with Tables and DataRelations to begin with. You are probably going to need to do that eventually anyway.
Hope this helps. Good luck.
|
|
|
|
|
Hello OldWarhorse,
Thanks a lot for your tips.
I will try the hashtable.
Regards
|
|
|
|
|
Hello, i'd like to know that does the MMControl exist in vb.net? if so...where do i add it from?
thanx in advance
|
|
|
|
|
The windows Media Player control is probably what you mean, you may need to add it to the toolbox.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I was wondering the same thing, but you can't add the media player control to the toolbox.
|
|
|
|
|
Why not? It works for me.
It's as easy as right-clicking the ToolBox and picking "Add/Remove Items..." under VS.NET 2002 and 2003 or "Choose Items..." under VS.NET 2005. A dialog opens up, click on the COM tab, find Windows Media Player in the list, put a check mark next to it and hit OK. Standard stuff for any COM-based component...
You've been giving out a bunch of bad advise. How long have you been doing this?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You can add the Windows Media Player control to the ToolBox by doing this[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Im not sure if windows media player and MMControl are the same thing. Cos i found a tutorial on adding sound recording to vb.net program and it used MMControl for recording sound....
|
|
|
|
|
True, but that's about as close as you're going to get without installing VB6.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I hope I don't insult anyone but I am trying to get any (if any) help developing for DocuCorp Product specifically the Documanager. THe company I work for currently is trying to migrate the thin client application design by the vendor(Docucorp) to upload and store files in this server. the problem is that this so call thin client was desing in believe or not using dynamic HMTL + a pseudo ASP calls. They provided documentation how to use their so call COM objects (and again believe or not i think they are vb5 or vb6) base code. We are tying to migrate this whole obsolete architecture to a more strong and robuted concept desing but so far nothing. Found out that their vb? libraries are not .NET interop which makes my project even difficult to get it going.
Has anyone out there done anything with any Docucorp product?
Just wonder
Thanks
Tony
|
|
|
|
|
Never heard of it. Truthfully, it's very unlikely someone with any experience with the product will see your post. In a few days, your post won't even be on the first page of the forum. Your best source of information on 3rd party controls is going to be the manufacturers own support site, Docucorp Support[^]
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave, Being there done that!
Tony Matute
|
|
|
|
|
I get it. It makes you wonder why some companies even charge for their libraries.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I'm writing a program that requires the user to choose either a single(or multiple) files or a whole folder. Is there a dialog for something like this. I know of the FolderBrowserDialog and OpenFileDialog but can I do this type of thing with either of those, I've tried but maybe I'm doing it wrong. Any help regarding this issue would be greatly appreciated, whether it be actual code or guide me to a site (or somewhere) for some more information. Thank you in advance!!
PS. If it matters at all, I am using VisualStudio.NET 2003
|
|
|
|
|
i believe with OpenFileDialog you can change the setting to either be single or multiple. it won't do the whole folder for you but if you do a ctrl-A (select all) i guess that's the same thing. it obviously won't handle sub folders.
|
|
|
|
|
Thanks for responding. I figured there wasn't an actual dialog that could do that but I thought I'd ask. Thanks again.
|
|
|
|
|
Hello,
I need export big texts of the my DataBase to MS Word, I using field of the DataBase in "Text" Format.
This is code I using:
==========================================================================
Dim varDR_DataReader As OleDbDataReader
objWord = CreateObject("Word.Application")
objWord.Documents.Open(Directory.GetCurrentDirectory & "\NewDoc.doc")
ReplaceVariable("@Book", varDR_DataReader ("Field_Book"))
ReplaceVariable("@Page", varDR_DataReader ("Field_Page"))
ReplaceVariable("@Description", varDR_DataReader ("Field_Description"))
objWord.visible = True
varDr_DataReader.Closed
Private Sub ReplaceVariable(ByVal Achar As String, ByVal Repl As String)
With objWord.Selection.Find
.Text = Achar.ToString
.Replacement.Text = Repl.ToString
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute = True
objWord.Selection.Select()
System.Windows.Forms.Clipboard.SetDataObject(Substituir)
objWord.Selection.Paste()
End While
End With
End Sub
===========================================================================
But, Field_Description it's very big, and caused overflow in ReplaceVariable.
Help me, please...
Thank's
Plinio
-- modified at 13:11 Friday 3rd November, 2006
|
|
|
|
|
hi, ive been trying to edit the global.aspx file to create an application connection to the SQL Server.
Code
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Data.SQLCLIENT" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Dim sqlConn As New SqlClient.SqlConnection
Dim sqlCommand As New SqlClient.SqlCommand
Dim ConectStr As String = "Data Source=DEVELOPMENT\SQLEXPRESS;Initial Catalog=Testdata;Integrated Security=True"
sqlConn = New SqlClient.SqlConnection("ConectStr")
sqlConn.Open()
Application("SQLConnection") = sqlConn
End Sub
Any ideas where im going wrong as this keeps failing.
Thanks in advance
I really do need help..... all this computer stuff is way over my head !!
|
|
|
|
|
You've got multiple problems with this.
First, ApplicationStart only executes the first time a page request is made to your site. It will never execute again.
Second, since this only executes once, anything this code does will never get executed for any subsequent page requests. Since web applications are stateless, your page code has to be written so that each page requests builds and destroys the objects it needs on EVERY request, not just the first one.
Any object you create in ApplicationStart will fall out of scope and not be usable anywhere in your page's code. So, building an SQL connection in ApplicationStart will not do you any good since they will no longer exist after ApplicationStart is done executing.
Lastly, you REALLY have to be specific in your posts as to what the code is supposed to be doing and supply any and all error messages you get along with the lines of code that the errors occur on. Without that, all you've done is pulled your car into the dealership and told the service guy "It's broke." How's he supposed to know what you're talking about?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I'd like to know how i can add all the file names of pictures in a directory to a listbox, and adding their extension in a column at the right of the file names. Anyone knows how to do this? (Sample code pls? )
--Zaegra--
|
|
|
|
|
Dim files() As String = IO.Directory.GetFiles(PathToDirectory)
|
|
|
|
|
I used a listview. I don't like the multi column behavior of a listbox. If you want to go through sub directories as well there is more to it obviously
1) Setup a listview
2) make sure you change it's 'view property to 'detail'
3) edit columns. add 2 call and them "File Name" and "Extension"
4) include the code below to populate it.
Imports System.IO
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oItem As ListViewItem
For Each sFile As String In Directory.GetFiles("c:\picturePath")
oItem = New ListViewItem(Mid(sFile, InStrRev(sFile, "\") + 1).ToLower)
oItem.SubItems.Add(Mid(sFile, InStrRev(sFile, ".") + 1))
Me.ListView1.Items.Add(oItem)
oItem = Nothing
Next
End Sub
End Class
|
|
|
|
|
Thanx, but is there a way to only display image file names in the list? The code you gave me adds all files in a dir
--Zaegra--
|
|
|
|