|
Loading and showing two forms will not keep your app open. Since your sub Main ends, so does your app. Really, what you should be doing is starting your app with a Form, since the message pump in this form will not end, and therefore your app, until the pump recieves a WM_QUIT message.
What is the purpose of having a Sub Main in your app?
RageInTheMachine9532
|
|
|
|
|
Well, i know that using a form as a startup object will keep it alive,
the main reason to use a 'Sub Main' is to get command line arguments, and i find it more organized to create an instance of the main form through code.
So a. commandline arguments
and b. neet code.
any suggestions?
Fade (Amit BS)
|
|
|
|
|
Fade (Amit BS) wrote:
a. commandline attributes
You don't need a Sub Main for command line arguments.
In you Form_Load event, or something else close to your app starting up, just use Environment.GetCommandLineArgs() to get a String array of the arguments.
Fade (Amit BS) wrote:
b. neet code
But a pain in the butt to keep an app running. It's MUCH easier to just have a main form and have that form launch the others than it is to keep a Sub Main in a relatively infinite loop watching for and waiting for all the open forms, most of which it has no clue even exist, to be closed and unloaded.
Think about it. Pick any app in Windows, like Word, VS.NET... They all have a main form and a bunch of helper forms that the main form launches and manages.
RageInTheMachine9532
|
|
|
|
|
ok,
You win
the command line arguments solution has tilted it to your favour, especially when there is no easy 'right' way to keep the app running via sub main.
thanx, i'll go back to using a main form.
Fade (Amit BS)
|
|
|
|
|
Hi im trying to retrieve data using a listview but get the following error when running:
An unhandled exception of type 'System.Data.SqlTypes.SqlNullValueException' occurred in system.data.dll
Additional information: Data is Null. This method or property cannot be called on Null values.
My code is as follows:
listitems.subItems.Add(IIf(IsDBNull(.GetString(1)), .GetString(1), ""))
can someone please help
Chrissy Callen
|
|
|
|
|
Chrissy Callen wrote:
listitems.subItems.Add(IIf(IsDBNull(.GetString(1)), .GetString(1), ""))
This statement is sitting inside a 'With' block. It would help to know what that 'With' is.
The GetString Method is being executed on a record that doesn't have a value. What you should be checking for first is if there is a value there, then execute GetString on it. Your trying to see if GetString returns a NULL, and if true, return the GetString NULL, if false, return an Empty string.
What you should be doing is this:
IIF( expression, Object if expression True, Object if expression False ) As Object
listitems.subItems.Add( IIf( IsDBNull(<whatever'With'Is>), "", .GetString(1) ) )
RageInTheMachine9532
|
|
|
|
|
It has to do with the IIf statement. It evaluates both conditions, regardless of whether the first one is true or not. In other words, it does not short-circuit. You need to use the regular VB If-Else-End If construct to make this logic work the way you want.
|
|
|
|
|
Hi
First sorry because my english is not very good.
I am a vb.net beginner , later I work with Visual C++.May be my problem is funny or maybe the datagrid is not a standard tool to work with data(add,remove,update,...) but I really have lots of problem with it.
I want to design a form that user should enter many records and at a time see the previous and next records.This Table has many fields I think it must be easier for the user to enter some of the fields in the columns of the datagrid and some of it in the form(textbox,combo,..) below the datagrid. and also some of the datagrid should be like combo box and some of it textbox and some of it Timeformat.I can connect the datagrid to the base and read the data . but I have not any control on the DataGrid,for example set a special query or change the column appearance to combo box or Mask edit or tabbed from one row of the column to the fields of the form for entering another fields of the record.how can I do these?
Can I use Ado not ado.net with VB.Net dataGrid ? if I can use ado and set the columns of the datagrid to the ado recordset it's so better.if I can do it please tell me how?Thanks a lot
|
|
|
|
|
Other than Source Safe, what version control systems have you used? Also, did they integrate with VB6, VS.NET? We are a very small company, and the cost of source safe is a big hit for us. Is there anything cheaper, as stable, as integrated?
Thanks.
Nursey
|
|
|
|
|
I have used CVSNT (www.cvsnt.org) with the TortoiseCVS client for a few months. But during this week I've changed to Subversion (subversion.tigris.org) with the TortoiseSVN client.
CVS is an older system very well known for Unix users and CVSNT is the Windows version of that system. As for Subversion, is targeted to replace CVS in the next years and from what I have seen they have a very good chance of doing just that.
Both Tortoise clients work in the same way. They are integrated in Windows Explorer and with just a few clicks you can do whatever you want with them. There are more clients around but those are the ones I like the most.
Both systems and clients are 100% free and they have worked very well for me with WindowsXP and .NET projects. I haven't found a reliable client to use CVSNT or Subversion directly from the IDE. But still, I managed to work with them and they have helped me a lot.
I hope I helped.
|
|
|
|
|
Thanks screaver. That's a lot of good info.
I'm really looking for IDE integration though.
I found one called Code Co Op, which is a peer-peer source control system, so there is no server, and its about $160 (US). Which is a bit more affordable. I'm nervous about using freeware things for mission critical aspects of a business, because you can't really afford a come back on somebody that did you a favour, but cost you millions 8-)
Nursey
|
|
|
|
|
|
simple question, im sure its around here somewhere, just couldnt see it.
if someone could send a link to it, if nothing else, that would be great.
just wondering how to program my application so that it can load a file into the program once the file type is opened. say, a notepad program opening .txt files, or winamp opening .mp3s. how do you do this?
edit: i know how to open and read files etc etc, i dont need help there.. im just wondering how i can load the file automatically if it is opened with the program, or where i put the code to do this.
Thanks alot, advanced.
------------------------
Jordan.
III
|
|
|
|
|
First, you app must support command line arguments. You'll have to pick out an open command and the filename to open. Notepad is launched by a command line that looks like this:
C:\WINDOWS\system32\NOTEPAD.EXE C:\Fullpath\filename.txt
Second, check out how .TXT files are associated to Notepad. Open an Explorer window and go to Tools\Folder Options. Click on the File Types tab and scroll down to TXT. Click on it to select it, then click on Advanced. Edit the Open command and you'll see what I'm talking about as far as command lines.
RageInTheMachine9532
|
|
|
|
|
hmm.. alrighty
thanks alot. ill check it out shortly. ill try and let you know how it goes.
------------------------
Jordan.
III
|
|
|
|
|
hopefully ull b auto-emailed about this reply
iv been looking in2 it and cant seem to find any help for vb.net. i found quite a few sites for vb6 code, it looks like. ive tried it and it doesnt recognize the "Command" variable, or whatever it would be called.
Private Sub Form_Load()
If Command$ <> "" Then
MsgBox "Application started by double clicking" & vbCr & Command$
End If
End Sub
i got this from here[^]. i searched vb.net's help index, and tried the ex. given with the "Command" thing. cant seem to get it.
also, it seems most apps use the command "%1" when opening files that are associated with the app..
any more help? ...appreciated
Thanks
------------------------
Jordan.
III
|
|
|
|
|
It's not Command$ -- that's old VB6 stuff.
Look into the Environment class. You'll use either Environment.CommandLine or Environment.GetCommandLineArgs(). Docs are here[^].
The '%1' is a replacable parameter. Remember DOS batch files? When that command line is executed, the %1 is replaced with the filename (complete path) you double-clicked on. If you double-click on, say, TestFile.txt, Explorer will convert this:
C:\WINDOWS\NOTEPAD.EXE "%1"
to this and execute it:
C:\WINDOWS\NOTEPAD.EXE "C:\Wherever this file sits\TestFile.txt"
RageInTheMachine9532
|
|
|
|
|
ok sorry for the nagging, etc.. heh
Thank you lots, ill read the lib info.
Again, thx.
------------------------
Jordan.
III
|
|
|
|
|
:-DNo problem!
RageInTheMachine9532
|
|
|
|
|
ok i think iv got it.. at least up to my requirements.
by simply using folder options/file types and manually associating the file type with the app, and adding %1, or %[any number] to the parameter list, i can work with it.
i simply assign a value to System.Environment.CommandLine() and it returns the app path, and the file path which was opened with it. i was thinking way to complex. my next step is to determine how to auto. associate the file types with the app, editing the registry from the app.
Thanks.
------------------------
Jordan.
III
|
|
|
|
|
I wrote a dll in C++ that I'm now calling from a vb app. everything works fine as far as the function is concerned, but after I terminate the VB app I get a _crtisvalidheappointer assertion.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
bdiamond wrote:
I wrote a dll in C++ that I'm now calling from a vb app.
If it's broken, I probably did it
It's broken, and yes, you did it.
The first place I'd look is the C++ .dll for resources not be cleared up before the .dll is unloaded. Also, I'd double check the types I've used calling the .dll and check to make sure the call types match. It might be that there is something being pushed onto the stack in the .dll and no being popped off. Could be tht your allocating memory in the .dll and no using the MATCHED free function to free that block of memory...
...could be a large range of things... Code samples would probably help.
RageInTheMachine9532
|
|
|
|
|
well, here's the entire function. I appreciate any help you can provide me with. thanks in advance!!
int Export(BSTR szServer, BSTR szDB, BSTR szUser, BSTR szPassword, BSTR szSQL)
{
int numOfRows=0;
int numOfFields=0;
int i=0,col=0;
int connected=0;
MYSQL *dbHandle;
MYSQL_RES *res;
MYSQL_FIELD *field;
MYSQL_ROW row;
char errmsg[512];
dbHandle=mysql_init((MYSQL*)0);
CString szDBFName;
CString strPath,strTblName;
try
{
CFileDialog dlg(FALSE,".DBF",NULL,OFN_ENABLESIZING | OFN_HIDEREADONLY,".dbf files (*.dbf)|*.dbf||");
if(dlg.DoModal() == IDOK)
{
szDBFName = dlg.GetPathName();
strTblName = dlg.GetFileName();
if((szDBFName.GetLength() || strTblName.GetLength() ) == 0)
{
AfxMessageBox("Export Canceled",MB_OK | MB_ICONINFORMATION);
return 0;
}
}
else
{
AfxMessageBox("Export Canceled",MB_OK | MB_ICONINFORMATION);
return 0;
}
int nPos = szDBFName.Find(strTblName,0);
strPath = szDBFName.Left(nPos);
if(mysql_real_connect(dbHandle,
(char*)szServer,
(char*)szUser,
(char*)szPassword,
(char*)szDB,
MYSQL_PORT,
NULL,
0))
{
connected=1;
}
else
{
sprintf(errmsg, "\nError: %s\n", mysql_error(dbHandle));
AfxMessageBox(errmsg);
connected = 0;
}
if(mysql_select_db(dbHandle,(char*)szDB))
{
sprintf(errmsg, "\nError: %s\n", mysql_error(dbHandle));
AfxMessageBox(errmsg);
return 0;
}
if(mysql_query(dbHandle,(char*)szSQL))
{
sprintf(errmsg, "\nError: %s\n", mysql_error(dbHandle));
AfxMessageBox(errmsg);
return 0;
}
res=mysql_store_result(dbHandle);
CDatabase *pDB = new CDatabase;
CString strConnect;
strConnect.Format("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=533;Dbq=%s;",strPath);
pDB->OpenEx(strConnect);
CString sColumns;
numOfRows = (int) mysql_num_rows(res);
numOfFields= (int) mysql_num_fields(res);
int * nFieldLen = new int[numOfFields];
int * nFieldDesc = new int[numOfFields];
for (i=0;i<numOfFields;i++)
{
field=mysql_fetch_field(res);
int nType = field->type;
int nLen = (int)field->length;
CString sCol;
nFieldDesc[i] = nType;
nFieldLen[i] = nLen;
switch(nType)
{
case FIELD_TYPE_ENUM:
case FIELD_TYPE_TINY:
case FIELD_TYPE_SHORT:
sCol.Format("%s %s,",field->name,"INTEGER ");
break;
case FIELD_TYPE_LONG:
sCol.Format("%s %s,",field->name,"LONG ");
break;
case FIELD_TYPE_FLOAT:
case FIELD_TYPE_DECIMAL:
sCol.Format("%s %s,",field->name,"FLOAT ");
break;
case FIELD_TYPE_DOUBLE:
sCol.Format("%s %s,",field->name,"DOUBLE ");
break;
case FIELD_TYPE_NULL:
sCol.Format("%s %s,",field->name,"int ");
break;
case FIELD_TYPE_LONGLONG:
case FIELD_TYPE_INT24:
sCol.Format("%s %s,",field->name,"LONG ");
break;
case FIELD_TYPE_YEAR:
case FIELD_TYPE_DATE:
case FIELD_TYPE_NEWDATE:
case FIELD_TYPE_TIME:
case FIELD_TYPE_DATETIME:
case FIELD_TYPE_TIMESTAMP:
sCol.Format("%s %s,",field->name,"DATE ");
break;
case FIELD_TYPE_SET:
sCol.Format("%s %s,",field->name,"int ");
break;
case FIELD_TYPE_TINY_BLOB:
case FIELD_TYPE_MEDIUM_BLOB:
case FIELD_TYPE_LONG_BLOB:
case FIELD_TYPE_BLOB:
sCol.Format("%s %s,",field->name,"MEMO ");
break;
case FIELD_TYPE_VAR_STRING:
case FIELD_TYPE_STRING:
sCol.Format("%s TEXT(%d),",field->name,nLen);
break;
}
sColumns += sCol;
}
sColumns = sColumns.Left(sColumns.GetLength() - 1);
sColumns = "CREATE TABLE " + strTblName + " (" + sColumns + ")";
pDB->ExecuteSQL(sColumns);
CDBFRecordset* m_Set = 0;
m_Set = new CDBFRecordset;
m_Set->Open(szDBFName);
for(i=0;i<numOfRows;i++)
{
int MaxLen = 0;
CString sYear,sMonth,sDay,sTime,sHour,sMinute,sSecond;
row=mysql_fetch_row( res );
m_Set->AddNew();
for (col=0;col<numOfFields;col++)
{
BOOL bDate = FALSE;
BOOL bMemo = FALSE;
field=mysql_fetch_field(res);
int nType = nFieldDesc[col];
MaxLen = 512;
switch(nType)
{
case FIELD_TYPE_TINY_BLOB:
case FIELD_TYPE_MEDIUM_BLOB:
case FIELD_TYPE_LONG_BLOB:
case FIELD_TYPE_BLOB:
bMemo = TRUE;
MaxLen = 10000;
break;
}
char * msg = new char[MaxLen];
sprintf(msg,"%s",row[col]);
CString str = msg;
COleDateTime * t;
switch(nType)
{
case FIELD_TYPE_YEAR:
case FIELD_TYPE_DATE:
case FIELD_TYPE_NEWDATE:
case FIELD_TYPE_TIME:
case FIELD_TYPE_DATETIME:
case FIELD_TYPE_TIMESTAMP:
str.Remove('-');
int len = str.GetLength();
sYear = str.Mid(0,4);
sMonth = str.Mid(4,2);
sDay = str.Mid(6,2);
if(len > 8)
{
sHour = str.Mid(8,2);
sMinute = str.Mid(10,2);
sSecond = str.Mid(12,2);
}
else
{
sHour = sMinute = sSecond = "0";
}
bDate = TRUE;
t = new COleDateTime(atoi(sYear),
atoi(sMonth),atoi(sDay),atoi(sHour),atoi(sMinute),atoi(sSecond));
break;
}
COleVariant fVar;
if(bDate)
fVar = *t;
else
fVar = str;
delete [] msg;
m_Set->SetFieldValue(col,fVar);
}
m_Set->Update();
}
AfxMessageBox("before deletions");
mysql_free_result( res ) ;
m_Set->Close();
if(m_Set)
delete m_Set;
if(pDB)
delete pDB;
AfxMessageBox("after deletions");
return 1;
}
catch(CDBException* e)
{
e->ReportError();
e->Delete();
}
catch(CException* e)
{
e->ReportError();
e->Delete();
}
catch(...)
{
AfxMessageBox("Unhandled Error.",MB_OK | MB_ICONINFORMATION);
}
return 0;
}
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Well, I've never used MySQL before, but since it pretty much follows MSSQL this shouldn't be a problem.
Something I've noticed with pDB is never told to Close. I'm assuming there is one considering there is an OpenEx(). And mysql_real_connect returned a dbhandle. I'm assuming there must be a function to close that handle and release the resources that it represents.
RageInTheMachine9532
|
|
|
|
|
I edited my code to include a dbHandle->free_me and a pDB->Close(), but I still get the same thing.
If it's broken, I probably did it
bdiamond
|
|
|
|
|