View Full Version : Converting VB6 code to C#
Drunken Durfin
03-05-2012, 06:05 PM
I am losing my fucking mind trying to figure out how to take a simple aspect of a little utility I wrote a few years ago and update it so that it works in C#.
Anyone out there that I can spend a few minutes via IM with me to point me in the right direction? Utility is used to display three fields of an existing Access database. The trick is that the structure of the database is constant, but the location and name of the database can be different, so I can't use the wizard thingy to bind everything that I need bound.
Thanks for booting DAO Microsoft, it REALLY made things easier.
Stanley Burrell
03-06-2012, 10:29 AM
Any luck? 0 luck on DAO legacy crap to see if there's a canned auto installer for any type of OS to ease-of-ax/s Access on this.
Can you get someone on-site or with a specific VPN entry to get into one of the DATs and write a broadcast binded just with VB frickin' 1.0 and do a few captures?
Drunken Durfin
03-06-2012, 12:11 PM
http://img.fannation.com/upload/user_image/image/151/127/full/dude-wait-what.jpg
Stanley Burrell
03-06-2012, 02:22 PM
Never mind, just tell us how you went about solving the issue.
Drunken Durfin
03-06-2012, 09:01 PM
Recode from scratch.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.Sql;
using System.Data.OleDb;
namespace Verify
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool bStop = false;
private void cmdOpenMDB_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Case Databases (*.mdb)|*.mdb";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
this.lblStatus.Visible = Visible;
Application.DoEvents();
txtCaseMDBPath.Text = openFileDialog1.FileName;
Cursor.Current = Cursors.WaitCursor;
//Add in necessiary controls
this.uniObjTableAdapter.Connection.ConnectionStrin g = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + openFileDialog1.FileName;// C:\\data\\shattered_alternate.accdb";
this.uniObjTableAdapter.Fill(this.trialDirectorDat aSet.UniObj);
this.lblStatus.Text = "Full Filepath:";
Cursor.Current = Cursors.Default;
cmdVerify.Enabled = true;
}
private void cmdVerify_Click(object sender, EventArgs e)
{
//Progress bar stuff
barProgress.Visible = true;
barProgress.Minimum = 1;
barProgress.Maximum = uniObjBindingSource.Count;
barProgress.Value = 1;
barProgress.Step = 1;
//Get values for record count and current position
int iRecords = uniObjBindingSource.Count;
int iCurrentRecord = uniObjBindingSource.Position;
//txtReport.Text = (1 + iCurrentRecord).ToString() + " of " + iRecords.ToString();
string rawPath = txtFilePath.Text;
string driveLetter = rawPath.Substring(1, 1);
//Parse out crappy TD filepath entry
int iLength;
iLength = rawPath.Length;
string trimmedPath;
trimmedPath = rawPath.Substring(4, (iLength - 4));
//Give File.Exists something to work with
lblStatus.Text = driveLetter + ":\\" + trimmedPath + "\\" + txtFileName.Text;
string checkFile = lblStatus.Text;
//Cycle through entire database
do
if (File.Exists(checkFile))
{
uniObjBindingSource.MoveNext();
lblStatus.Text = driveLetter + ":\\" + trimmedPath + "\\" + txtFileName.Text;
checkFile = lblStatus.Text;
iCurrentRecord = uniObjBindingSource.Position;
Application.DoEvents();
barProgress.PerformStep();
if(bStop)
{
break;
}
}
else
{
txtReport.AppendText("Not Found: " + checkFile + Environment.NewLine);
uniObjBindingSource.MoveNext();
lblStatus.Text = driveLetter + ":\\" + trimmedPath + "\\" + txtFileName.Text;
checkFile = lblStatus.Text;
iCurrentRecord = uniObjBindingSource.Position;
Application.DoEvents();
barProgress.PerformStep();
if (bStop)
{
break;
}
}
while(iCurrentRecord <= iRecords);
cmdSaveReport.Enabled = true;
}
private void cmdExit_Click(object sender, EventArgs e)
{
bStop = true;
this.Close();
}
private void cmdSaveReport_Click(object sender, EventArgs e)
{
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
saveFileDialog.FilterIndex = 1;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
// create a file stream
System.IO.FileStream fs = new System.IO.FileStream(saveFileDialog.FileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
// create a stream writer
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.ASCII);
// write to file (buffer)
sw.Write(txtReport.Text);
// flush buffer (I don't know why)
sw.Flush();
// close stream writer and file
sw.Close(); fs.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Commented out so utility is not connected to a database on load.
//this.uniObjTableAdapter.Fill(this.trialDirectorDat aSet.UniObj);
}
Having fits converting over to C#, but it has to be done.
Stanley Burrell
03-07-2012, 01:00 AM
I just wrote form1. Active, visible, maximized ... and a do beep. No binding wizard when trying to do what you are doing. It is a fucking black hole. Sorry.
Drunken Durfin
03-07-2012, 12:11 PM
It is a fucking black hole. Sorry.
Most of my side projects are. Maybe one day when I get sucked in to one of these, instead of pulling me into molecular spaghetti, it will transport me to another universe where I am a millionaire astronaut rock star body building champion.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.