Click here to Skip to main content
15,905,785 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Use event on Runtime Pin
JR2123-Jul-11 19:10
JR2123-Jul-11 19:10 
AnswerRe: Use event on Runtime Pin
Johan Hakkesteegt5-Jul-11 2:03
Johan Hakkesteegt5-Jul-11 2:03 
AnswerRe: Use event on Runtime Pin
Simon_Whale5-Jul-11 2:12
Simon_Whale5-Jul-11 2:12 
QuestionProblem using Package and Deployment Wizard Pin
Shouvik262-Jul-11 0:53
Shouvik262-Jul-11 0:53 
AnswerRe: Problem using Package and Deployment Wizard Pin
Dr.Walt Fair, PE2-Jul-11 18:58
professionalDr.Walt Fair, PE2-Jul-11 18:58 
QuestionExcel interop & filling columns from an array (VB.NET 3.5) Pin
Steven St. John1-Jul-11 6:50
Steven St. John1-Jul-11 6:50 
AnswerRe: Excel interop & filling columns from an array (VB.NET 3.5) Pin
Alan N1-Jul-11 10:56
Alan N1-Jul-11 10:56 
GeneralRe: Excel interop & filling columns from an array (VB.NET 3.5) [modified] Pin
Steven St. John1-Jul-11 13:15
Steven St. John1-Jul-11 13:15 
Smile | :)

I swear I was all over google... but using VB.net in my search may have backfired. Better to look at examples of people using VBA writing macros, and then translating. Your suggestion led me to this page[^] which led me to the odd "WorksheetFunction" methods. Here's the new code:

Private Sub ILIHistogramSheet()
    xlSheet = ReturnReferenceToNextSheet()
    xlSheet.Name = "ILI histograms"
    SupplyHeaders()

    Dim rows As Integer = mData(0).Trials(0).ILIHistogram.Keys.Count
    Dim row As Integer = 7
    Dim r As Excel.Range
    Dim col As Integer = 1

    r = DirectCast(xlSheet.Cells(row, col), Excel.Range).Resize(rows, 1)
    r.Value = xlApp.WorksheetFunction.Transpose(mData(0).Trials(0).ILIHistogram.Keys.ToArray)

    col = 2
    For Each ls As LickometrySession In mData
        For Each lt As LickometrySession.LickometryTrial In ls.Trials
            r = DirectCast(xlSheet.Cells(row, col), Excel.Range).Resize(rows, 1)
            r.Value = xlApp.WorksheetFunction.Transpose(lt.ILIHistogram.Values.ToArray)
        Next
        col += 1
    Next

    r = DirectCast(xlSheet.Cells(7, 1), Excel.Range).Resize(rows - 1, 1)
    r.Font.Bold = True
End Sub


The key statement is r.Value = xlApp.WorksheetFunction.Transpose(lt.ILIHistogram.Values.ToArray), where xlApp is a reference to an Excel.Application instance and ILIHistogram is the Dictionary(Of Integer, Integer) property that holds my data. The code above:

1. Gets an Excel.Range (r) in column 1 starting at row 7 and sized for the size of my array
2. Adds in one step all of my Keys
3. Starts a loop to circle through all of my custom objects holding all of my data
4. Gets a range each time one column wide and down as many rows as needed
5. Adds the data to the range in one step while transposing using the worksheet function

I'm using a relatively small dataset to test with, but already the advantage is huge. Before seeing your answer, I had coded it looping through my data, adding one cell at a time.

Old way = 233 milliseconds
New way = 32 milliseconds

Since I have 4 sheets to fill with data like this and will usually be dealing with much larger data sets, this is a nice save.

Thanks!

modified on Friday, July 1, 2011 7:55 PM

QuestionWebService monOccurs and maxOccurs Without Nillable [modified] Pin
KenBonny29-Jun-11 22:44
KenBonny29-Jun-11 22:44 
QuestionVBA text problem Pin
KORCARI28-Jun-11 10:51
KORCARI28-Jun-11 10:51 
AnswerRe: VBA text problem Pin
ChandraRam29-Jun-11 3:44
ChandraRam29-Jun-11 3:44 
AnswerRe: VBA text problem Pin
Dalek Dave29-Jun-11 5:44
professionalDalek Dave29-Jun-11 5:44 
QuestionInstaller [modified] Pin
KenBonny27-Jun-11 4:17
KenBonny27-Jun-11 4:17 
AnswerRe: Installer Pin
KenBonny27-Jun-11 21:22
KenBonny27-Jun-11 21:22 
QuestionDeviceID from CD Pin
JR21225-Jun-11 20:15
JR21225-Jun-11 20:15 
AnswerRe: DeviceID from CD Pin
JR21225-Jun-11 23:43
JR21225-Jun-11 23:43 
QuestionUsing LINQ to Objects to generate a frequency table - returned as a Dictionary [modified] Pin
Steven St. John25-Jun-11 5:28
Steven St. John25-Jun-11 5:28 
QuestionAdd Reference At Runtime Pin
Milad.Biroonvand23-Jun-11 8:47
Milad.Biroonvand23-Jun-11 8:47 
AnswerRe: Add Reference At Runtime Pin
Eddy Vluggen23-Jun-11 9:12
professionalEddy Vluggen23-Jun-11 9:12 
QuestionVB and MS Excel Pin
geekgautam23-Jun-11 3:07
geekgautam23-Jun-11 3:07 
AnswerRe: VB and MS Excel Pin
David Mujica23-Jun-11 3:28
David Mujica23-Jun-11 3:28 
GeneralRe: VB and MS Excel Pin
geekgautam23-Jun-11 18:26
geekgautam23-Jun-11 18:26 
GeneralRefresh Data Pin
David Mujica24-Jun-11 6:25
David Mujica24-Jun-11 6:25 
GeneralRe: Refresh Data Pin
geekgautam24-Jun-11 8:01
geekgautam24-Jun-11 8:01 
AnswerRe: VB and MS Excel Pin
Dalek Dave23-Jun-11 3:39
professionalDalek Dave23-Jun-11 3:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.