PDA

View Full Version : VB.net - Aiuto urgente


|Angelus|
20-12-2012, 19:56
Ciao a tutti,
vi contatto perchč sono al quanto disperato. Sono uno studente in ingegneria edile e sto portando avanti una tesi di progettazione parametrica sfruttando il software Grasshopper, un plug in del programma grafico Rhinoceros 4.
Grasshopper lavora come con una tavola di circuiti elettrici che rappresentano processi logici, e tra quelli utilizzabili trovo c#, vb.net e python. Su consiglio di un amico ho iniziato a fare alcune clip necessarie con vb.net, semplici soluzioni matematiche con l'uso di "if" e "for".
Di linguaggio di programmazione ne so poco niente, avendo usato solo matlab e, purtroppo, non potendo sfruttare l'integrazione tra i due.

Passiamo al problema:
per una gestione rapida dei materiali, ho scritto un foglio excel che contiene le caratteristiche degli stessi (peso proprio, caratteristiche meccaniche, caratteristiche termiche) dove ogni materiale č classificato per tramite un codice
http://img845.imageshack.us/img845/4714/tab1h.jpg
il codice nella dorma AABBCCC (AA posizone elemento, BB classe, CCC sottoclasse)
Dal programma grasshopper inserisco come input i parametri:
alpha,beta,gamma = che compongono il codice;
s = spessore dell'elemento
http://imageshack.us/a/img547/9970/scriptv.jpg
Ho compilato il seguente codice:
PARTE AUTOCOMPILATA DA GRASSHOPPER
Option Strict Off
Option Explicit On

'Import SDK and Framework namespaces
Imports Rhino
Imports Rhino.Geometry
Imports Rhino.Collections

Imports Grasshopper
Imports Grasshopper.Kernel
Imports Grasshopper.Kernel.Data
Imports Grasshopper.Kernel.Types

Imports GH_IO
Imports GH_IO.Serialization

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Linq
Imports System.Linq
Imports System.Data
Imports System.Drawing
Imports System.Reflection
Imports System.Collections
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Runtime.InteropServices



'Code generated by Grasshopper(R) (except for RunScript() content and Additional content)
'Copyright (C) 2012 - Robert McNeel & Associates
<System.Runtime.CompilerServices.CompilerGenerated()> _
Public Class Script_Instance
Inherits GH_ScriptInstance
'Implements IGH_ScriptInstance

#Region "Members"
''' <summary>List of error messages. Do not modify this list directly.</summary>
Private __err As New List(Of String)

''' <summary>List of print messages. Do not modify this list directly, use the Print() and Reflect() functions instead.</summary>
Private __out As New List(Of String)

''' <summary>Represents the current Rhino document.</summary>
Private doc As RhinoDoc = RhinoDoc.ActiveDoc

''' <summary>Represents the Script component which maintains this script.</summary>
Public owner As Grasshopper.Kernel.IGH_ActiveObject

''' <summary>Represents the number of times that RunScript has been called within this solution.</summary>
Public runCount As Int32
#End Region

#Region "Utility functions"
''' <summary>Print a String to the [Out] Parameter of the Script component.</summary>
''' <param name="text">String to print.</param>
Private Sub Print(ByVal text As String)
__out.Add(text)
End Sub

''' <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
''' <param name="format">String format.</param>
''' <param name="args">Formatting parameters.</param>
Private Sub Print(ByVal format As String, ByVal ParamArray args As Object())
__out.Add(String.Format(format, args))
End Sub

''' <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
''' <param name="obj">Object instance to parse.</param>
Private Sub Reflect(ByVal obj As Object)
__out.Add(GH_ScriptComponentUtilities.ReflectType_VB(obj))
End Sub

''' <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
''' <param name="obj">Object instance to parse.</param>
Private Sub Reflect(ByVal obj As Object, ByVal method_name As String)
__out.Add(GH_ScriptComponentUtilities.ReflectType_VB(obj, method_name))
End Sub
#End Region

''' <summary>
''' This procedure contains the user code. Input parameters are provided as ByVal arguments,
''' Output parameter are ByRef arguments. You don't have to assign output parameters,
''' they will be null by default.
''' </summary>


PARTE COMPILATA
Private Sub RunScript(ByVal file As Object, ByVal alpha As Object, ByVal beta As Object, ByVal gamma As Object, ByVal s As Object, ByRef cat As Object, ByRef tip As Object, ByRef des As Object)
Dim B As Object 'categoria
Dim C As Object 'tipo
Dim D As Object 'descrizione
Dim E As Object 'spessore fisso
Dim F As Object 'spessore minimo
Dim J As Object 'spessore massimo
Dim L As Object 'permeabilitā
Dim M As Object 'coefficiente di resistenza al vapore
Dim O As Object 'massa volumica [kg/m^3]
Dim P As Object 'massa superficiale [kg/m^2]
Dim Q As Object 'calore specifico
Dim R As Object 'conducibilitā di esercizio
Dim U As Object 'resistenza termica
Dim V As Object 'permeabilitā
Dim Z As Object 'tipo flusso

'codice di ricerca
Dim k As Object
k = alpha * 100000 + beta * 1000 + gamma

Dim x1 As Object
x1 = System.Diagnostics.Process.Start(file)

Dim wb As Object = x1.ActiveWorkbook(file)
Dim ws As Object = wb.ActiveSheet(1)
Dim Codice As Integer
Dim i As Long

For i = 2 To 700

'estrae il valore dalla cella (riga,colonna)
Codice = ws.Cells(i, 1)
If Codice = k Then
B = ws.Cells(k, 2)
C = ws.Cells(k, 3)
D = ws.Cells(k, 4)
E = ws.Cells(k, 5)
F = ws.Cells(k, 6)
J = ws.Cells(k, 7)
L = ws.Cells(k, 8)
M = ws.Cells(k, 9)
O = ws.Cells(k, 10)
P = ws.Cells(k, 11)
Q = ws.Cells(k, 12)
R = ws.Cells(k, 14)
U = ws.Cells(k, 15)
V = ws.Cells(k, 16)
Z = ws.Cells(k, 17)
End If


Next

'chiude tutto
wb.Close
x1.Quit

cat = B
tip = C
des = D
End Sub

'<Custom additional code>


'</Custom additional code>

End Class

Di seguito l'errore che mi segna.
http://img10.imageshack.us/img10/588/erroreqw.jpg
inoltre ad ogni variazione del valore mi riapre excel (invece vorrei che al massimo apra una volta e poi continui a leggerlo per fare l'estrazione dei dati per i materiali. Al momento non dā output.

L'idea č di far aprire al vb.net il foglio excel (possibilmente in background) ed avvia la ricerca della riga contenente il codice inserito, e su quella riga corrispondente al valore mi estragga tutti i parametri contenuti nelle colonne necessari per fare dei calcoli e cicli "if".

Sapete come posso risolvere questo problema di interazione con vb.net? o anche in C# se per i cicli if e for non cambia molto di linguaggio.
Grazie per le risposte.