|
Well, there's probably an article on CP somewhere, but it's really simple - bung a datagrid on your form, then call SetDataBinding on it with your array:
' Example - display an array of 3 items in a datagrid
Dim myArray as String(3) = { "Hi", "Hello", "Bonjour" }
' Haven't tested this, but should work ok
DataGrid1.SetDataBinding(myArray, "")
If you need something more complicated (eg, multiple columns), use a DataTable instead of an Array. All of this is documented in MSDN anyway.
--
Ian Darling
|
|
|
|
|
This is my first time here, so: hi guys! Hope your day does not suck. Mine is OK, but I'm banging my fragile head against a problem with converting UNIX standard epoch numbers to something fairly regular, date-wise.
I receive a timecode from a Perl program, written as seconds since 1970, the standard way of talking about time in the UNIX world. Then my VB component wants to log this thing, and well, I'd like to be able to record it like YYYY-MM-DD HH:MM, but so far I am stumped.
Some gotchas (add to this list if you can come up with more difficulties that could crop up during the writing of such a function):
* leap years
A few examples of timecodes from the last few weeks:
1054746806
1054555725
1056715898
OK, that is my question. Have you done this before?
Have a nice day, folks.
Olle
Lund, Sweden
|
|
|
|
|
After doing a nice function to calculate how many seconds have elapsed since 1970-01-01 00:00:00 a workmate came by and whistled that I should do a DateDiff()
<br />
DateDiff("s", CDate("1970-01-01 00:00:00"), Now)<br />
Which was correct. Sigh. I'll try and make the other conversion, now. From seconds into days and years and months and...
See you.
Olle,
Shamed in a corner, Lund, Sweden
|
|
|
|
|
I believe this will work, but I didn't actually test it against any known Epoch date values.
Private Function GetEpochDate(ByVal seconds As Long) As DateTime<br />
Dim BeginningOfTime As New DateTime(1970, 1, 1)<br />
Return BeginningOfTime.AddSeconds(seconds)<br />
End Function
|
|
|
|
|
I regret that I am now working with VB6, and I'm also sorry I didn't include that into my first posting. I bow my head in shame. DateAdd() is my next stop, I guess.
Yep, it was!
<br />
Public Function GetEpochToDate(ByVal seconds As Long) As Date<br />
GetEpochDate = DateAdd("s", seconds, CDate("1970-01-01 00:00:00"))<br />
End Function<br />
Public Function GetDateToEpoch(ByVal theDate As Date) As Long<br />
GetDateToEpoch = DateDiff("s", CDate("1970-01-01 00:00:00"), theDate)<br />
End Function<br />
Thank you, Matt!
|
|
|
|
|
|
I want to access active web page objects like text boxes from VB application. I know it could be done using ActiveX. Can anyone help me How To Do It.
AJC
|
|
|
|
|
Hello,
I need some sound advice, here is the scenario: I have a mdiChild form that contains a button that launches a owned (owned by the mdiChild) form. My questions is: What is the most effective way to pass data from the owned form to the appropriate member variables declared on the mdiChild form (owner)?
Thanks in advance,
Andrew
|
|
|
|
|
It's alright I figured it out. I created a custom constructor for the owned form that accepts an instance of the mdiChild form.
Example:
(Owned Form Declaration)
Public Sub New(ByRef mdiChildInstance As frmMdiChild)
MyBase.New()
_mdiChildInstance = mdiChildInstance
End Sub
(OwnedForm Instantiation - code is located on the MdiChild Form)
Public OwnedForm As New frmOwnedForm(Me)
I also created public properties for all of the member variables on mdiChild.
Does anyone see any red flags with the code above?
Thanks,
Andrew
|
|
|
|
|
The memory footprint of this kind of coding is a serious problem.
|
|
|
|
|
So what is your suggestion?
|
|
|
|
|
Why is it a serious problem? A form is just a class, and it's common practice to create and pass values to custom constructors, correct?
Andrew
|
|
|
|
|
A form is a class, but once instanciate it is an object that ocupies memory space. The bigger the object, the bigger the cost of passing it through constructors. Yes, if you pass it by reference instead you eliminate some of that cost because the CLR does not create a copy of the object. But it is better practice to pass smaller objects through constructors.
|
|
|
|
|
Thank you for the explanation. What you're saying makes absolute sense. Your help is much appreciated.
Thanks again,
Andrew
P.S What is a better way to pass data between mdiChild forms?
|
|
|
|
|
I can't for the life of me work out (or find samples on) how to read back the attribute of an entry in an Enum, for example:
Public Enum Colours<br />
<Description="Bright Red"> BrightRed = 0<br />
<Description="Brilliant Yellow"> BrightYellow = 1<br />
<Description="Puce"> Horrible = 2<br />
End Enum
I know it has something to do with Reflection, but that doesnt seem to help
Ultimately I want to write a function to able to do something like GetDescription(GetType(Colours))
Thanks, ro.
|
|
|
|
|
you mean something like this :
VB:
<font color="blue">Public</font> <font color="blue">Enum</font> Colours
BrightRed = 0
BrightYellow = 1
Horrible = 2
<font color="blue">End</font> <font color="blue">Enum</font>
<font color="blue">Private</font> <font color="blue">Sub</font> Button1_Click(<font color="blue">ByVal</font> sender <font color="blue">As</font> System.Object, <font color="blue">ByVal</font> e <font color="blue">As</font> System.EventArgs) <font color="blue">Handles</font> Button1.Click
<font color="blue">Dim</font> c <font color="blue">As</font> Colours
MessageBox.Show(GetColours(c.BrightRed))
<font color="blue">End</font> <font color="blue">Sub</font>
<font color="blue">Public</font> <font color="blue">Function</font> GetColours(<font color="blue">ByVal</font> i <font color="blue">As Integer</font>) <font color="blue">As String</font>
<font color="blue">Dim</font> clr <font color="blue">As</font> Colours
<font color="blue">Select Case</font> i <font color="darkgreen">'/// numerical value of the colour.</font>
<font color="blue">Case</font> clr.BrightRed
<font color="blue">Return</font> "you chose BrightRed" <font color="darkgreen">' <font color="blue">Case</font> clr.BrightYellow
<font color="blue">Return</font> "you chose BrightYellow"
<font color="blue">Case</font> clr.Horrible
<font color="blue">Return</font> "you chose Horrible"
<font color="blue">End Select</font>
<font color="blue">End</font> <font color="blue">Function</font>
hope that helps a little
<font color="blue">Private void</font> ExpectingTwins(<font color="blue">string</font> twins)
{
<font color="blue">switch</font>(twins)
{
<font color="blue">Case</font> ("twins on the way"):
MessageBox.Show("for mr and mrs dynamic","twins on the way");
<font color="blue">break</font>;
}
}
|
|
|
|
|
The following function should work for you ...
Imports System.ComponentModel<br />
Imports System.Reflection<br />
<br />
Private Function GetContentTypeValue(ByVal value As Colours) As String<br />
Dim fi As FieldInfo = value.GetType.GetField(value.ToString)<br />
Dim attributes As DescriptionAttribute() = CType(fi.GetCustomAttributes(GetType(DescriptionAttribute), False), DescriptionAttribute())<br />
If attributes.Length > 0 Then<br />
Return attributes(0).Value<br />
Else<br />
Return String.Empty<br />
End If<br />
End Function
|
|
|
|
|
I have the following code in a vb script to open the cd-rom drives:
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection
if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
End If
But, how do I close the cd-rom drive?
|
|
|
|
|
|
Hi,
I am developing a Visual Basic Project that takes a lot of data from a DB and generates an Excel Chart. Then, I have to save the chart in HTML format, because the chart is viewed in a web page. I have to put a background color accordying to the web site style. But Excel don't accept the background color that I need to fix. It seems that color palette in Excel is limited to few colors. I tried also with a background picture, but it covers only the chart area, and the HTML generated code creates an image for the chart and the body background color remains white...
Anybody knows how can I resolve this problem?
Thanks in advance,
LAURA
|
|
|
|
|
OK, i have this mp3 renaming tool written in VB and I've added a context menu item for mp3 files called "MP3Rename". When I right click on an mp3 file and choose MP3Rename from the context menu, it runs my program in the background to rename the mp3 file. This worls perfectly when I select one file, but if I select multiple files, my program doesn't even get executed. I know this because I've placed a MsgBox statement on the first line of my code, but the message box never appears with multiple files (it does with a single file). Anyone have any ideas why selecting multiple files does absolutely nothing? Thanks.
|
|
|
|
|
Hi all,
I have a problem. I have 1 exe and several dll's. From my exe (mostly an MDI form) I call to the different dll's which contain mainly forms. When I want to close such a form, what's the best method 'Close()' or 'Dispose()'. You see, I want to be sure that the complete dll is removed from memory each time, since it is called by 'objAssembly.CreateInstance'...
Greetings,
Sigurd
|
|
|
|
|
Someone correct me if I'm wrong here:
If you didn't explicitly call the Win32 API function LoadLibrary(), you can't unload it.
DLL load and unload is handled automatically by the runtime (in both VB and VB.NET.) When your App loads, the runtime attempts to resolve all external references and loads the appropriate DLL's automatically. Then your app is able to call the functions you wanted. When you're done using the resources of the DLL, it WILL NOT unload. This won't happen (automatically, anyway) until your Application quits because that's when your releasing your references to the DLL.
RageInTheMachine9532
|
|
|
|
|
I am developing an application and i have lot of forms and i would like to keep these following features for simple text data(included in Textbox).
Undo
cut
Copy
Paste
Is there any method to generalize the situation.
Thank you in Advance.
John Joseph
Programmer in VB, VC
|
|
|
|
|
I'am looking for a away to enable CutCopyMode, run a Macro and then disable
CutCopyMode when I click on a button.
|
|
|
|