.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Newby question

3 REPLIES 3
Reply
Message 1 of 4
richie_hodgson
391 Views, 3 Replies

Newby question

I currently have a VBA routine that utilises a dialogue box which has a pull down list box in which I have a list of standard scales, I also have a file search option to look for .csv or .txt files, and the usual quit button, I also have access to sharp develop. what is the process for recreating such a beastie in Sharpdevelop for .net. I also have code which I want to migrate but I think one at a time at this moment.

Richie
3 REPLIES 3
Message 2 of 4
Hallex
in reply to: richie_hodgson

Welcome on board

Here is the quick code

Create Windows Application project

Drop ListBox and 2 Buttons on form

Add this code into the form module

Imports System
Imports System.Text
Imports System.Data
Imports System.IO

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim itemarray As ArrayList = New ArrayList()
        Dim myStream As Stream = Nothing
        Dim filedial As New OpenFileDialog()
        filedial.InitialDirectory = "c:\"
        filedial.Filter = "Text files (*.txt)|*.txt|Delimited files (*.csv)|*.csv"
        filedial.Multiselect = False
        filedial.FilterIndex = 1
        filedial.RestoreDirectory = True

        If filedial.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Try
                Me.ListBox1.Items.Clear()
                Dim filename As String = filedial.FileName
                itemarray = ReadTxtFile(filename, Me.ListBox1)
   
            Catch Ex As System.Exception
                MessageBox.Show("Cannot read file from disk. Original error: " & vbCr & Ex.Message)
            End Try
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Public Function ReadTxtFile(ByVal filename As String, ByVal lbox As ListBox) As ArrayList
        Dim rdata As New ArrayList()
        Dim fs As FileStream = Nothing
        Dim txf As StreamReader
        Dim s As String
        Try
            fs = New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)
            txf = New StreamReader(fs)
            s = txf.ReadLine

            Do Until s Is Nothing
                lbox.Items.Add(s)
                s = txf.ReadLine
            Loop

        Catch ex As System.Exception
            Throw New System.Exception("If the file existed it was closed")
        Finally
            fs.Close()
        End Try
        Return rdata
    End Function


    Private Sub ListBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.Click
        Dim strscale As String = ListBox1.Text
        MessageBox.Show(strscale)
        ''--> work with selected scale here
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "ListBox Example"
        Me.Button1.Text = "Select Data File"
        Me.Button2.Text = "Exit Form"
    End Sub
End Class

 Hope this will you get started

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4

Thanks for that, I was in a bit of a hurry yesterday and forgot to add a vital single text  box which asks for a Height for height above datum calculations. Is it too much to ask for you to add this to the form. The next question is where you put

--> work with selected scale here, on my VBA form I used the following

scales.AddItem "5"

scales.AddItem "10" ....

 

do I do something like

 

strscale.AddItem "5"

strscale.AddiItem "10".... 

Richie
Message 4 of 4
Hallex
in reply to: richie_hodgson

Ah, do you want to add custom scales...

It's so easily:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim scalearray() As String = New String() {"1:1", "1:2", "1:5", "1:10", "1:25", "1:50", "1:100"}
        Me.ListBox1.DataSource = scalearray
    End Sub

 

And also here is a good link I think it would be useful for you too

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost